XState doesn't work with either embroider-safe or embroider-optimized scenarios?
See original GitHub issueI noticed this on CI, but I’m testing locally with
node_modules/.bin/ember try:one embroider-safe --skip-cleanup --- ember s -p 4201
both imports don’t work:
import {...} from 'xstate';
import {...} from 'xstate/es';
XState’s relevant package.json entries:
"main": "lib/index.js",
"module": "es/index.js",
"types": "lib/index.d.ts",
(I confirm that all these files exists)
Versions of things at the time of running:
"@embroider/compat": "0.40.0",
"@embroider/core": "0.40.0",
"@embroider/test-setup": "^0.40.0",
"@embroider/webpack": "0.40.0",
"xstate": "^4.18.0"
XState, in my addon, is both a devDependency and a peerDependency – but moving xstate to a regular dependency doesn’t change anything.
My addon’s embroider config:
'use strict';
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
module.exports = function (defaults) {
let app = new EmberAddon(defaults, {});
const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app, {
packageRules: [
{
package: 'dummy',
components: {
'{{toggle}}': { safeToIgnore: true },
'{{toggle-machine}}': { safeToIgnore: true },
'{{report}}': { safeToIgnore: true },
},
},
],
});
};
The error I get:
Uncaught Error: Could not find module `xstate/es` imported from `(require)`
missingModule loader.js:247
findModule loader.js:258
requireModule loader.js:24
<anonymous> es.js:1
js chunk.62c601a0ec9371568b5d.js:213
__webpack_require__ chunk.a285fd98a411feb3069e.js:64
<anonymous> statechart-manager.js:5
it’s the same if I say just “xstate”, shown here:
Uncaught Error: Could not find module `xstate` imported from `(require)`
missingModule loader.js:247
findModule loader.js:258
requireModule loader.js:24
<anonymous> xstate.js:1
js chunk.380d08940477220a3a0d.js:213
__webpack_require__ chunk.a285fd98a411feb3069e.js:64
<anonymous> statechart-manager.js:5
Something strange I noticed when I was looking at the contents of /tmp/embroider/87df42
is that xstate
is the only symlinked node_modules.
but why?
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
embroider/SPEC.md at main - GitHub
Another way to state the problem is that apps and addons all push whatever code they want into the final built app. Whereas...
Read more >v2 Addon Format (Embroider Compatibility) - Ember RFCs
This RFC defines a new package format that is designed to make Ember packages (meaning both apps and addons) statically analyzable and more ......
Read more >How To Design a Logo for Embroidery - RushOrderTees
Instructions for designing or simplifying a logo for custom embroidery, plus a brief overview of the process.
Read more >Best Computers to Use with an Embroidery Machine in 2022
Looking for the best computer to use with your embroidery machine? I'll show you what to look for and recommend a few of...
Read more >Thread Talk: The Debate I Don't Want to Have
Thread grain advocates contend that stitching “with the grain” of the thread will result in smoother stitching, in fewer knots as you work...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The whole “by side-effect” thing happens under ember-auto-import in a classic build because in that case we’re flattening down all dependencies into a flat namespace, to interoperate with the runtime AMD loader. Under embroider, we don’t need to do that, which is why the dummy app having access to xstate doesn’t leak into giving the addon access to xstate.
This has nothing to do with xstate.
You’re trying to import from NPM in a v1 addon without ember-auto-import. That never works. Embroider follows the same rules as the traditional build in this respect. Move ember-auto-import from
devDependencies
todependencies
so your addon is allowed to use it, and that fixes the problem.Your test suite is failing to notice that your addon is actually broken under non-embroider builds, too. The problem is that the dummy app directly imports from xstate, which is allowed because the dummy app can use ember-auto-import as a devDependency. As a side effect, this makes xstate available to the addon code too. But as soon as the addon tried to run without the dummy app, it would be broken.