Post AWnFXpgmP5WR9Hp2K8 by chuang@noc.social
 (DIR) More posts by chuang@noc.social
 (DIR) Post #AWnFXnUeZCdML68K92 by nilesh@fosstodon.org
       2022-12-13T16:06:22Z
       
       0 likes, 0 repeats
       
       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/learndbI'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?
       
 (DIR) Post #AWnFXokdtF1AEycbho by nilesh@fosstodon.org
       2022-12-13T16:15:48Z
       
       0 likes, 0 repeats
       
       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?
       
 (DIR) Post #AWnFXpgmP5WR9Hp2K8 by chuang@noc.social
       2022-12-13T16:34:39Z
       
       1 likes, 0 repeats
       
       @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.