我有nodeJS/express应用程序和rollup绑定程序。我使用rollup配置文件,命令在package.json中定义,如:"build":"env _OPTIONS=‘prod’rollup - config倾诉/ROLup.config.js“。当我尝试“”时,出现了错误:
> deep@1.0.0 watch C:\Users\1\Desktop\sprout-test\sprout-backend
> env ROLLUP_OPTIONS='dev' rollup --config configs/rollup.config.js --watch
C:\Users\1\Desktop\sprout-test\sprout-backend\node_modules\rollup\dist\shared\loadConfigFile.js:484
? (await import(url.pathToFileURL(fileName).href)).default
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\1\Desktop\sprout-test\sprout-backend\node_modules\rollup\dist\bin\rollup:23:25)这是导致错误的函数,在汇总源代码中:
async function loadConfigFile(fileName, commandOptions) {
const extension = path.extname(fileName);
const configFileExport = extension === '.mjs' && supportsNativeESM()
? (await import(url.pathToFileURL(fileName).href)).default
: extension === '.cjs'
? getDefaultFromCjs(require(fileName))
: await getDefaultFromTranspiledConfigFile(fileName, commandOptions.silent);
return getConfigList(configFileExport, commandOptions);
}这个函数(上面)放在第481行的node_modules/rollup/dist/shared/loadConfigFile.js中。进程将此函数中的动态导入语法作为语法错误(意外令牌“导入”)。看起来,在进程执行我自己的配置文件之前,rollup会抛出这个错误。根据这一点,我假设汇总源代码会导致这个错误,而不是我的源代码,因为我的代码没有被加载和执行的机会。如果我是对的,玩插件等是毫无意义的,因为汇总甚至没有达到这个点,它加载我的插件(前)。我吐露或解析我的代码。根据docs,rollup应该支持它自己的文件和我的配置文件中的“导入/导出”语法,而不需要任何额外的配置。
下面是我的开发依赖项列表,其中有我使用的汇总版本:
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-json": "^4.0.2",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-run": "^2.0.2",
"eslint": "^6.8.0",
"lint-staged": "^10.1.6",
"prettier": "^2.0.4",
"rollup": "^2.6.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-includepaths": "^0.2.3",
"rollup-plugin-uglify": "^6.0.4"
}为了以防万一,我列出了整个列表,但正如我所说的,我认为我的babel插件在这里不相关,因为错误是在装载rollup.config.js之前抛出的,其中加载了babel配置。重要的是,项目在我创建repo (windows 10)的机器上运行时没有错误,在我克隆repo (windows 7)的机器上失败--所以节点、git和npm版本是不同的。但是根据package.json文件,两台机器上的汇总版本是相同的。
我的节点版本(win 7):8.11.3
我的npm版本(win 7):6.4.14
我尝试过(win7) "npm卸载汇总-g“(当然,如果它的安装是全局的,并且与项目中的版本冲突),但是它不起作用。现在我不知道该怎么做,我也没有找到与我的问题相似的资源。如有任何建议,我将不胜感激。
发布于 2020-04-30 20:59:22
在您的NodeJS机器上使用的Win7版本与您正在使用的汇总版本不兼容,您可以通过检查https://github.com/rollup/rollup/blob/master/package.json#L141找到这个版本。
通过使用engine属性,NPM包可以指定它们与哪个版本的NodeJS兼容,在这种情况下,需要版本10或更高版本。
https://stackoverflow.com/questions/61531954
复制相似问题