Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importSync breaks the builds of apps consuming type=module packages #1672

Open
Tracked by #1773
NullVoxPopuli opened this issue Nov 17, 2023 · 1 comment
Open
Tracked by #1773

Comments

@NullVoxPopuli
Copy link
Collaborator

NullVoxPopuli commented Nov 17, 2023

repro:

  • create a v2 addon
  • add type=module to the package's package.json
  • add a src/example.css file
  • add code to src/index.js
    import { importSync } from '@embroider/macros';
    
    export const two = 2;
    
    importSync('./example.css');
    Note, in my actual project, importSync is wrapped in a macroCondition.
    if it were not wrapped in a macroCondition I would just use regular import './example.css';
  • build the addon
  • change the test-app ember-cli-build.js to directly use embroider (compat or strict doesn't matter):
    const { Webpack } = require('@embroider/webpack');
    return require('@embroider/compat').compatBuild(app, Webpack, {
      skipBabel: [
        {
           package: 'qunit',
        },
      ],
    });
  • start the app
  • receive error
    Module not found: Error: Can't resolve '../../node_modules/.pnpm/@embroider+macros@1.13.3/node_modules/@embroider/macros/src/addon/es-compat2' in '/home/nvp/Development$TMPDIR/type-module-test/type-module-test/dist/index.js'
    Did you mean 'es-compat2.js'?
    BREAKING CHANGE: The request '../../node_modules/.pnpm/@embroider+macros@1.13.3/node_modules/@embroider/macros/src/addon/es-compat2' failed to resolve only because it was resolved as fully specified
    (probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
    The extension in the request is mandatory for it to be fully specified.
    Add the extension to the request.

To see that type=module appears to work:

  • remove importSync
  • rebuild addon
  • restart app

Here is a PR proving the above in a real addon: universal-ember/ember-primitives#33

@mansona
Copy link
Member

mansona commented Dec 13, 2023

is this still a problem with #1692 ?

NullVoxPopuli added a commit to universal-ember/ember-primitives that referenced this issue Dec 13, 2023
NullVoxPopuli added a commit to universal-ember/ember-primitives that referenced this issue Dec 13, 2023
Update embroider deps

Upgrade stuff

Fix type

Update lockfile

Lockfile

Remove importSync to demonstrate 'fix' for embroider-build/embroider#1672

Wip

Use unstable

eh
NullVoxPopuli added a commit to universal-ember/ember-primitives that referenced this issue Dec 13, 2023
Update embroider deps

Upgrade stuff

Fix type

Update lockfile

Lockfile

Remove importSync to demonstrate 'fix' for embroider-build/embroider#1672

Wip

Use unstable

eh

eh
NullVoxPopuli added a commit to universal-ember/ember-primitives that referenced this issue Dec 13, 2023
Update embroider deps

Upgrade stuff

Fix type

Update lockfile

Lockfile

Remove importSync to demonstrate 'fix' for embroider-build/embroider#1672

Wip

Use unstable

eh

eh

lints
NullVoxPopuli added a commit to universal-ember/ember-primitives that referenced this issue Dec 13, 2023
Update embroider deps

Upgrade stuff

Fix type

Update lockfile

Lockfile

Remove importSync to demonstrate 'fix' for embroider-build/embroider#1672

Wip

Use unstable

eh

eh

lints

eh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants