-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Description
I'm trying to import xstate using Node@13 native support for ES Modules.
Expected Result
Should be able to import as specified is the docs
Actual Result
The requested module 'xstate' does not provide an export named 'Machine'
Reproduction
Simply run the following code after installing xstate and run it with Node >= 13.0.0
import { Machine } from 'xstate';Additional context
I've tried both setting the "type": "module" in my package.json and renaming the script file to *.mjs, but the error still persists.
Out of curiosity, I decided to use the import-star syntax to see what happened:
import * as xs from 'xstate';
console.log(xs);It outputs:
[Module] {
default: {
matchesState: [Function: matchesState],
mapState: [Function: mapState],
StateNode: [Function: StateNode],
State: [Function: State] {
from: [Function (anonymous)],
create: [Function (anonymous)],
inert: [Function (anonymous)]
},
Machine: [Function: Machine],
createMachine: [Function: createMachine],
send: [Function: send],
sendParent: [Function: sendParent],
sendUpdate: [Function: sendUpdate],
assign: [Function (anonymous)],
doneInvoke: [Function: doneInvoke],
forwardTo: [Function: forwardTo],
interpret: [Function: interpret],
Interpreter: [Function: Interpreter] {
defaultOptions: [Object],
interpret: [Function: interpret]
},
spawn: [Function: spawn],
matchState: [Function: matchState],
actions: {
raise: [Function: raise],
send: [Function: send],
sendParent: [Function: sendParent],
sendUpdate: [Function: sendUpdate],
log: [Function: log],
cancel: [Function (anonymous)],
start: [Function: start],
stop: [Function: stop],
assign: [Function (anonymous)],
after: [Function: after],
done: [Function: done],
respond: [Function: respond],
forwardTo: [Function: forwardTo],
escalate: [Function: escalate]
},
ActionTypes: {
Start: 'xstate.start',
Stop: 'xstate.stop',
Raise: 'xstate.raise',
Send: 'xstate.send',
Cancel: 'xstate.cancel',
NullEvent: '',
Assign: 'xstate.assign',
After: 'xstate.after',
DoneState: 'done.state',
DoneInvoke: 'done.invoke',
Log: 'xstate.log',
Init: 'xstate.init',
Invoke: 'xstate.invoke',
ErrorExecution: 'error.execution',
ErrorCommunication: 'error.communication',
ErrorPlatform: 'error.platform',
ErrorCustom: 'xstate.error',
Update: 'xstate.update',
Pure: 'xstate.pure'
},
SpecialTargets: { Parent: '#_parent', Internal: '#_internal' }
}
}
So it looks like even though state has an ESM target, it doesn't seem it's being properly loaded, because this looks like the CommonJS exported module.
For reference, here's my package.json:
{
"name": "xstate-labs",
"version": "1.0.0",
"module": "index.js",
"license": "MIT",
"type": "module",
"dependencies": {
"xstate": "^4.7.7"
}
}Tested with [email protected].
Metadata
Metadata
Assignees
Labels
Type
Projects
Status