jsoneditor-react icon indicating copy to clipboard operation
jsoneditor-react copied to clipboard

SyntaxError: Cannot use import statement outside a module

Open zelth opened this issue 5 years ago • 7 comments

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}
    />

zelth avatar Jan 06 '20 11:01 zelth

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

vankop avatar Jan 06 '20 17:01 vankop

I followed the instructions above with a react app

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

zelth avatar Jan 07 '20 02:01 zelth

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"
    }
  },

ialsowalkdogs avatar Feb 17 '20 12:02 ialsowalkdogs

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

kory-stiger avatar Sep 14 '20 16:09 kory-stiger

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?

Barik85 avatar May 19 '21 16:05 Barik85

See also issue #34

bruderda avatar Jun 10 '21 21:06 bruderda