Reputation: 103
I've got nodeJS/express application with rollup bundler. I use rollup config file, with command defined in package.json, like so: "build": "env ROLLUP_OPTIONS='prod' rollup --config configs/rollup.config.js". When i try "npm run build", i've got error:
> [email protected] 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)
This is the function that causes error, in rollup source code:
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);
}
This function (above) is placed in node_modules/rollup/dist/shared/loadConfigFile.js in line 481. Process takes dynamic import syntax in this function as syntax error (unexpected token "import"). It seems that rollup throws this error before process executes my own config file. According to this, I assume that rollup source code causes this error, not MINE source code, since my code has no chance to be loaded and executed. If i'm right, playing with plugins etc. is pointless, since rollup does not even reach this point, where it loads my plugins (ex. babel), my configs or parse my code. According to docs, rollup should support "import/export" syntax in its own files and in my config files as well, without any extra configuration.
Heres my dev-dependencies list, with Rollup version that i use:
"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"
}
I placed whole list just in case, but as i said, i think my babel plugins are irrelevant here, since error is thrown before rollup loads rollup.config.js, where babel configuration is loaded. What is important, project runs without errors on machine where i created repo (windows 10), and fails on machine where i cloned repo (windows 7) - so node, git and npm versions are different here and there. But according to package.json file, rollup version is the same on both machines.
My node version (win 7): 8.11.3
My npm version (win 7): 6.4.14
I tried (win7) "npm uninstall rollup -g" (just for sure, in case if its installed globally and conflicted with in-project version) but it does not work. Right now I have no idea what to do, and I have found no resources about problem similar to mine. I would appreciate any advice.
Upvotes: 3
Views: 4460
Reputation: 1012
The NodeJS version you are using on your Win7 machine is not compatible with the version of Rollup you are using, you can find this out by checking https://github.com/rollup/rollup/blob/master/package.json#L141.
By using the engine property a NPM package can specify which versions of NodeJS they are compatible with, in this case version 10 or higher is needed.
Upvotes: 4