-1

I published my first package using npm. However, when I import it in Codesandbox it gives me a warning

Error when converting '/node_modules/protected-react-routes-generators/src/index.js' esmodule to commonjs: Cannot read property 'type' of null

This is my github Repo

Also when i installed it from NPM, it gives me this error enter image description here

I don't know what this error is, any clue ? Thanks!

2 Answers2

1

Babel can't compile jsx extensions. Install:

npm install --save-dev @babel/preset-react

And add to your .babelrc file:

{"presets": ["@babel/preset-react"]}

Paul Barrié
  • 320
  • 3
  • 12
  • could you please explain ? because i don't understand what do you mean by jsx extensions. also i don't have `babelrc` should i write it in `package.json` – Mohammed Saber Mohammed Feb 12 '21 at 21:20
  • considering that i'm using CRA so how can edit babel configs – Mohammed Saber Mohammed Feb 12 '21 at 22:11
  • 1
    In your external packages (in `node_modules` folder), you have files with extension `.jsx` which is a syntaxic extension of javascript commonly used in React. But your javascript compiler (babel) can't natively handle this type of files. So you have to add some specifications to its configuration file which is `.babelrc` you can simply add at the same location of your package.json – Paul Barrié Feb 15 '21 at 20:52
0

I made a mistake which I published the package as a react component without build it to be a raw javascript