`@embroider/macros` and type=module
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
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)
Current issue (and the one causing the two tests to hang):
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?
Each time I push, I'm going to be cancelling the workflow so as to not hog CI