当我要导入和导出并在nodejs上运行时,出现类似这样的错误
(function (exports, require, module, __filename, __dirname) { export default function try(test){
^^^^^^
SyntaxError: Unexpected token export
我的package.json就是这样
{
"name": "importExport",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0"
},
"dependencies": {
"babel-cli": "^6.26.0"
}
}
和我的.babelrc
{
"presets": ["env", "es2015"]
}
我也尝试过使用babel和我尝试过的许多方法在互联网上遵循本教程,但是它仍然无法在导入和导出中运行我的node index.js
任何人都可以帮助我解决此问题,我应该设置并重新安装吗?
我也尝试了节点--experimental-modules,使用文件.mjs
,并且当我尝试导入和导出仍然不起作用