'rollup --config gives : [!] SyntaxError: Unexpected token 'export'

I'm trying to learn how to use rollup to package some javascript, following some tutorial on the net. I stuck at the very beginning trying to use a config file. With command line everything seems OK, but with a config file it ends with an Unexpected token 'export' syntax error.

My config is Windows 11 with:

c:\dev\rollup-test>node --version
v16.14.2
c:\dev\rollup-test>rollup --version
rollup v2.70.1

Config file :

c:\dev\rollup-test>type rollup.config.js
export default {
    input: './src/main.js',
    output: {
      file: './build/bundle.js',
      format: 'es'
    }
  };

The javascript file src\main.js:

c:\dev\rollup-test>type src\main.js
console.log('hi there!');

In CLI mode, everything seems OK:

c:\dev\rollup-test>rollup ./src/main.js --file ./build/bundle.js --format es

./src/main.js → ./build/bundle.js...
created ./build/bundle.js in 29ms

Trying to use the config file above:

c:\dev\rollup-test>rollup --config
[!] SyntaxError: Unexpected token 'export'
c:\dev.local\rollup-test\rollup.config.js:1
export default {
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1032:15)
    at Module._compile (node:internal/modules/cjs/loader:1067:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Object.require.extensions.<computed> [as .js] (C:\Users\joelh\AppData\Roaming\npm\node_modules\rollup\dist\shared\loadConfigFile.js:617:13)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at loadConfigFromBundledFile (C:\Users\joelh\AppData\Roaming\npm\node_modules\rollup\dist\shared\loadConfigFile.js:622:42)

c:\dev\rollup-test>

There's probably something so obvious, but alas I can't see it. Can anyone help me to go further ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source