@nilesh To utilize the ESM support in recent node.js releases, you either add "type": "module" to your package.json, or rename second.js to second.mjs.
Conversation
Notices
-
chuang@noc.social's status on Sunday, 18-Jun-2023 05:25:04 JST chuang - Disinformation Purveyor :verified_think: likes this.
-
nilesh (nilesh@fosstodon.org)'s status on Sunday, 18-Jun-2023 05:25:06 JST nilesh Here is the minimal version of my problem:
In a fresh nodejs project (created via `npm init`), I have:
`first.js` that has contents:
```
export let x = 45;`
```And `second.js` that has:
```
import { x } from 'first.js'
console.log(x);
```Assume that I don't have the freedom to edit `first.js`. What do I need to do to make `node second.js` run correctly?
I have tried almost everything that NodeJS suggests. How is rollup able to load and run such a file?
-
nilesh (nilesh@fosstodon.org)'s status on Sunday, 18-Jun-2023 05:25:07 JST nilesh I need Javascript help.
I don't understand the Javascript module variants (ES / AMD / CJS / IIFE / UMD) at all. This trips me up every single time.
Check this repo: https://github.com/learn-awesome/learndb
I'm running a modern version of NodeJS (18.7.0). But why is it that the command `node_modules/rollup/dist/bin/rollup -c` works perfectly fine but running `node rollup.config.js` (or any other file using code like "import x from Y") throws a syntax error?
How is rollup able to overcome a SYNTAX ERROR?