embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
337 stars 136 forks source link

v2 addon + embroider/macros results in build-time error from consuming (classic) app #1111

Closed NullVoxPopuli closed 2 years ago

NullVoxPopuli commented 2 years ago

Minimal Reproduction: https://github.com/NullVoxPopuli/ember-addon-v2-embroider-macros-test

I found this over in ember-resources while trying to hack together some extra reactivity for apps using ember-concurrency v1 (since v2 has things that "just work", some folks using ember-concurrency v1 don't have the same niceties (like reactive isFinished property (for some reason, still investigating (could totally be because I broke something with proxies), but that's orthogonal to this issue))

My v2 addon only has:

import {macroCondition, dependencySatisfies, importSync} from '@embroider/macros';

if (macroCondition(dependencySatisfies('ember-concurrency', '^1.0.0'))) {
  let {get} = importSync('@ember/object');

  console.log(get);
}

export const two = 2;

and is using the sample rollup and babel config from the addon-dev folder.

The error is:

ERROR in ../../my-addon/dist/index.js 1:74-176
Module not found: Error: Can't resolve '../../node_modules/@embroider/macros/src/addon/runtime' in '<repo>/my-addon/dist'
Did you mean 'runtime.js'?

ERROR in ../../my-addon/dist/index.js 1:0-74
Module not found: Error: Can't resolve '../../node_modules/@embroider/macros/src/addon/es-compat' in '<repo>/my-addon/dist'
Did you mean 'es-compat.js'?
full console output ``` ❯ ember test was unable to use: "events", fell back to: "polling" Environment: test tests/_the_-test.ts:3:21 - error TS2307: Cannot find module 'my-addon' or its corresponding type declarations. 3 import { two } from 'my-addon'; ~~~~~~~~~~ tests/_the_-test.ts:5:36 - error TS6133: 'hooks' is declared but its value is never read. 5 module('v2 addon tests', function (hooks) { ~~~~~ assets by chunk 881 KiB (id hint: vendors) asset chunk.vendors-node_modules_qunit_qunit_qunit_js.18e076bd4f2d052ef031.js 811 KiB [emitted] [immutable] [big] (id hint: vendors) asset chunk.vendors-node_modules_ember-welcome-page_dist_components_welcome-page_js.a8421fe4ef5ca8359317.js 69.7 KiB [emitted] [immutable] (id hint: vendors) asset chunk.app.630d73180ea8bf75cf6d.js 21.4 KiB [emitted] [immutable] (name: app) asset chunk.tests.6b4d8eaf63f1ad662f89.js 21.3 KiB [emitted] [immutable] (name: tests) Entrypoint app 91.1 KiB = chunk.vendors-node_modules_ember-welcome-page_dist_components_welcome-page_js.a8421fe4ef5ca8359317.js 69.7 KiB chunk.app.630d73180ea8bf75cf6d.js 21.4 KiB Entrypoint tests [big] 832 KiB = chunk.vendors-node_modules_qunit_qunit_qunit_js.18e076bd4f2d052ef031.js 811 KiB chunk.tests.6b4d8eaf63f1ad662f89.js 21.3 KiB runtime modules 6.53 KiB 12 modules built modules 204 KiB [built] cacheable modules 204 KiB modules by path ../../node_modules/ 203 KiB 7 modules modules by path ../../../../../../../tmp/broccoli-11560070OTP8SsQnazs/cache-311-webpack_bundler_ember_auto_import_webpack/*.js 1.19 KiB ../../../../../../../tmp/broccoli-11560070OTP8SsQnazs/cache-311-webpack_bundler_ember_auto_import_webpack/l.js 50 bytes [built] [code generated] + 2 modules ../../my-addon/dist/index.js 284 bytes [built] [code generated] modules by path external "@ember/ 210 bytes external "@ember/template-factory" 42 bytes [built] [code generated] external "@ember/component" 42 bytes [built] [code generated] external "@ember/application" 42 bytes [built] [code generated] external "@ember/version" 42 bytes [built] [code generated] external "@ember/object" 42 bytes [built] [code generated] external "@glimmer/component" 42 bytes [built] [code generated] ERROR in ../../my-addon/dist/index.js 1:0-74 Module not found: Error: Can't resolve '../../node_modules/@embroider/macros/src/addon/es-compat' in '/my-addon/dist' Did you mean 'es-compat.js'? BREAKING CHANGE: The request '../../node_modules/@embroider/macros/src/addon/es-compat' 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. resolve '../../node_modules/@embroider/macros/src/addon/es-compat' in '/my-addon/dist' using description file: /my-addon/package.json (relative path: ./dist) Field 'browser' doesn't contain a valid alias configuration using description file: /node_modules/@embroider/macros/package.json (relative path: ./src/addon/es-compat) Field 'browser' doesn't contain a valid alias configuration /node_modules/@embroider/macros/src/addon/es-compat doesn't exist @ ../../../../../../../tmp/broccoli-11560070OTP8SsQnazs/cache-311-webpack_bundler_ember_auto_import_webpack/tests.js 15:42-61 ERROR in ../../my-addon/dist/index.js 1:74-176 Module not found: Error: Can't resolve '../../node_modules/@embroider/macros/src/addon/runtime' in '/my-addon/dist' Did you mean 'runtime.js'? BREAKING CHANGE: The request '../../node_modules/@embroider/macros/src/addon/runtime' 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. resolve '../../node_modules/@embroider/macros/src/addon/runtime' in '/my-addon/dist' using description file: /my-addon/package.json (relative path: ./dist) Field 'browser' doesn't contain a valid alias configuration using description file: /node_modules/@embroider/macros/package.json (relative path: ./src/addon/runtime) Field 'browser' doesn't contain a valid alias configuration /node_modules/@embroider/macros/src/addon/runtime doesn't exist @ ../../../../../../../tmp/broccoli-11560070OTP8SsQnazs/cache-311-webpack_bundler_ember_auto_import_webpack/tests.js 15:42-61 cleaning up... Build Error (WebpackBundler) webpack returned errors to ember-auto-import} ```
dist/index.js ```js ❯ cat dist/index.js import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros'; if (macroCondition(dependencySatisfies('ember-concurrency', '^1.0.0'))) { let { get } = importSync('@ember/object'); console.log(get); } const two = 2; export { two }; ```
ef4 commented 2 years ago

Are you using "type": "module" in package.json again?

NullVoxPopuli commented 2 years ago

I am -- but I have the Rule.type set as well:

ember-cli-build.js ```js 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { let app = new EmberApp(defaults, { autoImport: { watchDependencies: [Object.keys(require('./package').dependencies)], webpack: { devtool: 'inline-source-map', module: { rules: [{ test: /\.(js|ts)$/, type: 'javascript/auto' }], }, }, }, }); const { maybeEmbroider } = require('@embroider/test-setup'); return maybeEmbroider(app, { packagerOptions: { webpackConfig: { devtool: 'inline-source-map', module: { rules: [{ test: /\.(js|ts)$/, type: 'javascript/auto' }], }, }, }, }); }; ```
NullVoxPopuli commented 2 years ago

Removing type: module resolves the issue 😅