我正在尝试发布一个npm包,当在我的包导入过程中进行本地测试时,我会得到以下错误:
Uncaught: SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import这是我的package.js内容:
{
"name": "gedflod",
"version": "0.0.1",
"description": "A gedflod nodejs package for doing some thing",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ged-flod/gedflod.git"
},
"keywords": [
"ged",
"flod",
"ged-flod",
"gedflod",
],
"author": "ged-flod",
"license": "MIT",
"bugs": {
"url": "https://github.com/ged-flod/gedflod/issues"
},
"homepage": "https://github.com/ged-flod/gedflods#readme",
"dependencies": {
"axios": "^0.26.0"
}
}你能帮帮我吗。
发布于 2022-07-15 14:57:59
如another response中所示,您需要调用import函数:
$ node
Welcome to Node.js v16.6.0.
Type ".help" for more information.
> const {myFunction} = await import('./src/myFunction.js')
> myFunction(...)我知道这是从Node.js 13开始工作的,但我只能确认它在Node.js v16.6.0中工作。
https://stackoverflow.com/questions/71371459
复制相似问题