Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Cannot use import statement outside a module #24

Open
zelth opened this issue Jan 6, 2020 · 7 comments
Open

SyntaxError: Cannot use import statement outside a module #24

zelth opened this issue Jan 6, 2020 · 7 comments

Comments

@zelth
Copy link

zelth commented Jan 6, 2020

any ideas on this? I've followed

import { JsonEditor as Editor } from 'jsoneditor-react';
import 'jsoneditor-react/es/editor.min.css';
later in render method:

    <Editor
        value={yourJson}
        onChange={this.handleChange}
    />
@vankop
Copy link
Owner

vankop commented Jan 6, 2020

Thanks for creating issue, could you please provide a minimal reproducible repo?

@zelth
Copy link
Author

zelth commented Jan 7, 2020

I followed the instructions above with a react app

and this is the error
SyntaxError: Cannot use import statement outside a module

@ialsowalkdogs
Copy link

ialsowalkdogs commented Feb 17, 2020

I had this issue while running Jest tests with my React project setup with [email protected]. Adding identity-obj-proxy as devDependency and adding the following to my Jest config resolved the issue for me:

"jest": {
    "transformIgnorePatterns": [
      "node_modules/(?!(jsoneditor-react/))"
    ],
    "moduleNameMapper": {
      "\\.css$": "identity-obj-proxy"
    }
  },

@kory-stiger
Copy link

I had this issue while running Jest tests with my React project setup with [email protected]. Adding identity-obj-proxy as devDependency and adding the following to my Jest config resolved the issue for me:

"jest": {
    "transformIgnorePatterns": [
      "node_modules/(?!(jsoneditor-react/))"
    ],
    "moduleNameMapper": {
      "\\.css$": "identity-obj-proxy"
    }
  },

Worked for me!

A couple notes:

  • I didn't need the moduleNameMapper part
  • I had to put it in my package.json
  • I also had to add the jsoneditor package as well like this "node_modules/(?!(jsoneditor-react|jsoneditor)/)"
  • This post helped me understand why I needed it: https://stackoverflow.com/a/55803188/13154904

@Barik85
Copy link

Barik85 commented May 19, 2021

I tried this

"jest": {
    "transformIgnorePatterns": [
      "node_modules/(?!(jsoneditor-react/))"
    ],
    "moduleNameMapper": {
      "\\.css$": "identity-obj-proxy"
    }
  },

But no result.
When running test i got "SyntaxError: Cannot use import statement outside a module".
I'am using creat-react-app + typescript
Any other desicions?

@bruderda
Copy link

bruderda commented Jun 10, 2021

See also issue #34

@sonaliraut-29
Copy link

My project had craco so below settings worked for me

configure(webpackConfig) {
   return cracoBabelLoader.overrideWebpackConfig({
     webpackConfig,
     pluginOptions: {
       includes: [
         __dirname + '/node_modules/yocto-queue',
         // new settings
         __dirname + '/node_modules/jsoneditor-react',
         __dirname + '/node_modules/jsoneditor',
       ],
     },
   })
 },
  transformIgnorePatterns: [
       //new settings
       '/node_modules/(?!p-limit|yocto-queue|react-photoswipe-gallery|photoswipe|jsoneditor-react|jsoneditor).+\\.js$',
  ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants