Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda