vankop / jsoneditor-react

react wrapper implementation for https://github.com/josdejong/jsoneditor
MIT License
263 stars 106 forks source link

SyntaxError: Cannot use import statement outside a module #24

Open zelth opened 4 years ago

zelth commented 4 years ago

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 commented 4 years ago

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

zelth commented 4 years ago

I followed the instructions above with a react app

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

ialsowalkdogs commented 4 years ago

I had this issue while running Jest tests with my React project setup with react-scripts@3.3.1. 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 commented 4 years ago

I had this issue while running Jest tests with my React project setup with react-scripts@3.3.1. 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:

Barik85 commented 3 years ago

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 commented 3 years ago

See also issue #34

sonaliraut-29 commented 2 weeks ago

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$',
     ],