Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
Uncaught SyntaxError: Cannot use import statement outside a module when import custom lib in google chrome extension

I am create a javascript lib and tried to import into my project, I tried to added dependencies into the google chrome extension code like this in the package.json:

"js-wheel": "git+https://github.com/jiangxiaoqiang/js-wheel.git",

and import modual in the google chrome extension project like this:

import { Auth,Validate } from "js-wheel";

when I run this code, the console shows error like this:

Uncaught SyntaxError: Cannot use import statement outside a module

this is the js-wheel package.json:

{
  "name": "js-wheel",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/jiangxiaoqiang/js-wheel.git"
  },
  "author": "jiangtingqiang@gmail.com",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/jiangxiaoqiang/js-wheel/issues"
  },
  "homepage": "https://github.com/jiangxiaoqiang/js-wheel#readme"
}

I have already tried to define the js-wheel to module, why still shows this error? where am I doing wrong? what should I do to fix this problem? In the public lib, I define the index.js like this:

import BaseMethods from "./src/utils/data/checker";
import Validate from "./src/utils/data/validate";
import Auth from "./src/auth/extension/auth";

export default {
    BaseMethods,
    Validate,
    Auth
}

and define the export function like this way:

const Validate = {
    
    mobileCheck: (mobile) => {
        let reg = /^[1][3,4,5,7,8][0-9]{9}$/
        return reg.test(mobile)
    }
}

export default Validate

I searched from intenet and tell me to tweak the package.json type to module, but still not fix this problem. I found the error was throw in the js-wheel internal from this line:

import BaseMethods from "./src/utils/data/checker";

why could not using this way to import in the js-wheel ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!