`SyntaxError: Cannot use import statement outside a module` in `@coreui/utils/src/index.js:1`
See original GitHub issueWhen writing tests for views, I always get the above exception during import of coreui components.
I wrote a simple test for rendering of the dashboard component:
src/views/dashboard/Dashboard.test.js
import React from 'react';
import {shallow} from 'enzyme/build';
import Dashboard from './Dashboard';
it('mounts without crashing', () => {
const wrapper = shallow(<Dashboard />);
wrapper.unmount()
});
~/d/coreui-free-react-admin-template $ npm run test
FAIL src/views/dashboard/Dashboard.test.js
● Test suite failed to run
/Users/sweh/dev/coreui-free-react-admin-template/node_modules/@coreui/utils/src/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import deepObjectsMerge from './deep-objects-merge'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (node_modules/@coreui/react/lib/fade/CFade.js:12:12)
Can you please provide a working test example for a view?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
"Uncaught SyntaxError: Cannot use import statement outside ...
The possible reasons for the SyntaxError: Cannot use import statement outside a module error is you are trying to run the file independently....
Read more >Cannot use import statement outside a module [React ...
When building a web application, you may encounter the SyntaxError: Cannot use import statement outside a module error.
Read more >How to solve: cannot use import statement outside a module
When you see the error message Uncaught SyntaxError: cannot use import statement outside a module, it means you're using an import statement ......
Read more >How to Fix "SyntaxError: Cannot use import statement outside ...
In this post, we'll learn more about the "SyntaxError: Cannot use import statement outside a module" error and how to fix it in...
Read more >How to fix "cannot use import statement outside a module"
Here is how to fix the error Uncaught SyntaxError: cannot use import statement outside a module in JavaScript.
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 Free
Top 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
I’m getting this error too, plz help me:
/Users/macbook/WebstormProjects/coreui-free-react-admin-template/node_modules/@coreui/icons/js/index.js:1 ({“Object.<anonymous>”:function(module,exports,require,__dirname,__filename,global,jest){import { brandSet } from ‘./brand/brand-set.js’ ^^^^^^
Another hotfix (tested on Dashboard)
in package.json
jest
section:We will probably fix it by default in the next
@coreui/react
minor release.