embroider icon indicating copy to clipboard operation
embroider copied to clipboard

`@embroider/macros` and type=module

Open NullVoxPopuli opened this issue 1 year ago • 3 comments

Extracted from https://github.com/embroider-build/embroider/pull/1572 (which has more issues to fix (wrong css path, for example)

Two fixes here (specifically for type=module):

  • [x] es-compat2 module was not resolvable (needed the js extensions)
  • [ ] importSync doesn't work with relative imports

NullVoxPopuli avatar May 07 '24 14:05 NullVoxPopuli

According to:

require() of ES Module /tmp/tmp-31383035liZVSdehi7p/node_modules/v2-addon/addon-main.js 
  from <.pnpm>/[email protected]/node_modules/ember-cli/lib/models/package-info-cache/package-info.js 
  not supported.
addon-main.js is treated as an ES module file as it is a .js file 
  whose nearest parent package.json contains "type": "module" which declares all .js files 
  in that package scope as ES modules.
Instead rename addon-main.js to end in .cjs, change the requiring code to use dynamic 
  import() which is available in all CommonJS modules, or change "type": "module" to 
  "type": "commonjs" in /tmp/tmp-31383035liZVSdehi7p/node_modules/v2-addon/package.json 
  to treat all .js files as CommonJS (using .mjs for all ES modules instead).

It is required that addon-main.js be cjs.

I had reverted that change earlier to reduce diff, forgetting that .js is not allowed to be ambiguous with type=module (the ambiguity is relied on for current non-type=module v2 addons)

NullVoxPopuli avatar May 07 '24 22:05 NullVoxPopuli

Current issue (and the one causing the two tests to hang): image

Died on test #1: Could not find module `./side-effecting.js` imported from `(require)`

it seems that importSync isn't working on relative imports perhaps?

NullVoxPopuli avatar May 08 '24 21:05 NullVoxPopuli

Each time I push, I'm going to be cancelling the workflow so as to not hog CI

NullVoxPopuli avatar May 08 '24 21:05 NullVoxPopuli