javascript - "Import React from 'react' " not working getting : "Reference error, can't find variable require' - TagMerge
1"Import React from 'react' " not working getting : "Reference error, can't find variable require'"Import React from 'react' " not working getting : "Reference error, can't find variable require'

"Import React from 'react' " not working getting : "Reference error, can't find variable require'

Asked 1 years ago
0
1 answers

I think you need to add the transform expectation to the script import As T.J.Crowder said, it looks like babel is transpiling to use require (CommonJS) I have not used babel standalone myself but I think you need this.

https://babeljs.io/docs/en/babel-plugin-transform-modules-umd <script src=... data-plugins="transform-es2015-modules-umd" type="text/babel" />

Personally, I use the Webpack bundler so the node module resolution handles this at transpile.

Source: link

Recent Questions on javascript

    Programming Languages