Can't import the named export 'nin' from non EcmaScript module
See original GitHub issueDescribe the bug Get the following error:
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5035-5036
Can't import the named export '$all' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5076-5077
Can't import the named export '$elemMatch' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:4983-4984
Can't import the named export '$eq' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5086-5087
Can't import the named export '$exists' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5008-5009
Can't import the named export '$gt' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5015-5016
Can't import the named export '$gte' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5021-5022
Can't import the named export '$in' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:4995-4996
Can't import the named export '$lt' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5002-5003
Can't import the named export '$lte' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:4989-4990
Can't import the named export '$ne' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5028-5029
Can't import the named export '$nin' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5063-5064
Can't import the named export '$options' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5052-5053
Can't import the named export '$regex' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5043-5044
Can't import the named export '$size' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:955-956
Can't import the named export 'CompoundCondition' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:910-911
Can't import the named export 'FieldCondition' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:1223-1224
Can't import the named export 'FieldCondition' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:2006-2007
Can't import the named export 'FieldCondition' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:1203-1204
Can't import the named export 'ITSELF' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/js/dist/es6m/index.mjs 1:597-598
Can't import the named export 'ITSELF' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/js/dist/es6m/index.mjs 1:1566-1567
Can't import the named export 'ITSELF' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/js/dist/es6m/index.mjs 1:1867-1868
Can't import the named export 'ITSELF' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:2054-2055
Can't import the named export 'NULL_CONDITION' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:2306-2307
Can't import the named export 'ObjectQueryParser' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5145-5146
Can't import the named export 'all' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5187-5188
Can't import the named export 'and' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:2427-2428
Can't import the named export 'buildAnd' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5207-5208
Can't import the named export 'createFactory' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5265-5266
Can't import the named export 'createFactory' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/js/dist/es6m/index.mjs 1:971-972
Can't import the named export 'createInterpreter' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5172-5173
Can't import the named export 'elemMatch' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5101-5102
Can't import the named export 'eq' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5181-5182
Can't import the named export 'exists' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5122-5123
Can't import the named export 'gt' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5128-5129
Can't import the named export 'gte' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5111-5112
Can't import the named export 'lt' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5117-5118
Can't import the named export 'lte' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5106-5107
Can't import the named export 'ne' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5139-5140
Can't import the named export 'nin' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:625-626
Can't import the named export 'optimizedCompoundCondition' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5160-5161
Can't import the named export 'regex' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5152-5153
Can't import the named export 'size' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@casl/ability/dist/es6m/index.mjs 1:5133-5134
Can't import the named export 'within' from non EcmaScript module (only default export is available)
ERROR in ../node_modules/@ucast/mongo/dist/es6m/index.mjs 1:169-238
Can't reexport the named export 'defaultInstructionParsers' from non EcmaScript module (only default export is available)
To Reproduce Steps to reproduce the behavior:
- Created a yarn monorepo w/ an angular project.
- Using
commonjs
as my tsconfig module,es2015
,dom
, andes6
as my libs,es2015
as my target. - Compile app
I am not even trying to use the angular bindings – when I do drop it into my module’s imports, I get errors about Ivy compatibility/ngcc, even though I’ve run ngcc.
CASL Version
@casl/ability
- 5.1.1
Environment: TS 4.0.3, Node 12.13.0, Angular 11.0.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Can't import the named export XXXX from non EcmaScript ...
the solution is to make sure that you have a webpack.config.js file in the root of your project directory that looks something like...
Read more >Can't import the named export 'SetArray' from non EcmaScript ...
Can't import the named export 'SetArray' from non EcmaScript module (only default export is available). Environment. System:
Read more >Can't import the named export from non EcmaScript module
Hi My site name is stupefied-lamarr-20c8d9 On the server side of my app I have lambda functions and within those I'm using apollo-server-lambda...
Read more >can't import from non ecmascript module - You.com
Can't import the named export XXXX from non EcmaScript module (only default ... the solution is to make sure that you have a...
Read more >"Can't import the named export from non EcmaScript module ...
KJS: "Can't import the named export from non EcmaScript module (only default export is available)" with react-map-gl-draw external interface. Relates to 1.
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
This worked for me too, but I had to replace the single quotes with escaped double quotes (on windows).
@paolosanchi Thanks a lot! This solution works both in dev mode and prod mode. The
webpack-config
trick withjavascript/auto
did not work when running--prod
.EDIT: for those that don’t want to add a dependency on shx
I ended up writing a small script to do the patching:
Create a file
fix-casl-mjs-webpack-issues.js
in package.json
The latest release of @casl/angular fixes ngcc related issue.
Regarding ESM modules: I found this issue regarding angular cli and some additional context. The issue is that when webpack imports dependencies inside
.mjs
files, webpack checks onlymain
andbrowser
fields in package.json.main
is usually points tocommonjs
andbrowser
I think usually points to some global vars. So, there is no reliable way to fix this for webpack4.So, I suggest to use one of this ways:
.mjs
files to be of typejavascript/auto
as in example repo. As a downside, your bundle size will be a bit biggerresolve.mainFields
and excludees2015
out of it, so webpack won’t bundle.mjs
file at all (usemodule
property which is a ES5 +ESM). As a downside, you can deliver a modern build for usersexports
field inpackage.json
and properly handles chains of ESM importspostinstall
hook and shx to rename.mjs
to.js
while angular cli uses webpack 4. In your app package.json: