2
votes

In a new React project, I'm getting this error when trying to import a component from node_modules (subplayer as can be seen from my package.json). The error further suggests to

Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation. If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.

So I created a babel.config.json in the same location as package.json with the following content

 {
    "presets": ["@babel/preset-react", "@babel/preset-env"],
    "plugins": ["@babel/plugin-transform-react-jsx", "@babel/plugin-syntax-jsx"]
}

My package.json contains the following:

    {
  "name": "projectname",
  "version": "0.1.0",
  "main": "./build/index.js",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.9",
    "@testing-library/react": "^11.2.5",
    "@testing-library/user-event": "^12.6.3",
    "bootstrap": "^4.6.0",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.3",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.2",
    "subplayer": "file:tmp/subplayer-2.0.0.tgz",
    "web-vitals": "^1.1.0"
  },
  
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
1

1 Answers

1
votes

you may want to install the dependencies npm i @babel/preset-react @babel/preset-env @babel/plugin-transform-react-jsx @babel/plugin-syntax-jsx -D