I am working on a nodeJS/express application with a rollup bundler. My rollup configuration file defines a command in the package.json like this: "build": "env ROLLUP_OPTIONS='prod' rollup --config configs/rollup.config.js". However, when I run "npm run build", I encounter an error:
> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cca8a9a9bc8cfde2fce2fc">[email protected]</a> 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)
The issue appears to be within the loadConfigFile function in the 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 seems to be causing a syntax error (unexpected token "import") due to dynamic import syntax, which suggests that the error originates from the rollup source code itself rather than my own code. It is preventing my config file from being loaded and executed. Despite having the necessary babel plugins listed in my dev-dependencies, the error persists. Interestingly, the project runs smoothly on a Windows 7 machine but encounters issues on a Windows 10 machine, indicating potential discrepancies in node, git, and npm versions.
My node version (win 7): 8.11.3
My npm version (win 7): 6.4.14
Attempts to resolve the issue by uninstalling rollup globally have been unsuccessful. As I search for solutions, any advice would be greatly appreciated.