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 ?