Home > Software engineering >  Dependencies error while trying to use country selector in my react code
Dependencies error while trying to use country selector in my react code

Time:12-09

I am trying to modify a code in .jsx to include a country selector and for that I am using the country-region-selector package using npm

After I install it in my ubuntu, and I am trying to run the code however I am getting this error :

     [ERROR] Could not resolve "react"

    ../../node_modules/react-country-region-selector/dist/rcrs.es.js:1:48:
      1 │ import React, { Component, PureComponent } from 'react';
        ╵                                                 ~~~~~~~

  You can mark the path "react" as external to exclude it from the bundle, which will remove this
  error.

11:29:46 AM [vite] error while updating dependencies:
Error: Build failed with 1 error:
../../node_modules/react-country-region-selector/dist/rcrs.es.js:1:48: ERROR: Could not resolve "react"
    at failureErrorWithLog (/home/shamma/my-experiment/client/node_modules/esbuild/lib/main.js:1605:15)
    at /home/shamma/my-experiment/client/node_modules/esbuild/lib/main.js:1251:28
    at runOnEndCallbacks (/home/shamma/my-experiment/client/node_modules/esbuild/lib/main.js:1034:63)
    at buildResponseToResult (/home/shamma/my-experiment/client/node_modules/esbuild/lib/main.js:1249:7)
    at /home/shamma/my-experiment/client/node_modules/esbuild/lib/main.js:1358:14
    at /home/shamma/my-experiment/client/node_modules/esbuild/lib/main.js:666:9
    at handleIncomingPacket (/home/shamma/my-experiment/client/node_modules/esbuild/lib/main.js:763:9)
    at Socket.readFromStdout (/home/shamma/my-experiment/client/node_modules/esbuild/lib/main.js:632:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
Vite Error, /node_modules/.vite/deps/react-country-region-selector.js?v=8daa6a38 optimized info should be defined

The line of code I am using in my code to include the package it this -->

import { CountryDropdown, RegionDropdown, CountryRegionData } from 'react-country-region-selector';

I looked online and I install the peer dependencies and save props using npm like that -->

(base) shamma@shamma-ThinkPad-13-2nd-Gen:~$ sudo npm-install-peers
This package doesn't seem to have any peerDependencies
(base) shamma@shamma-ThinkPad-13-2nd-Gen:~$ 
(base) shamma@shamma-ThinkPad-13-2nd-Gen:~$ sudo npm install --save prop-types
npm WARN [email protected] requires a peer of react@^15.0.0 || ^16.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react-dom@^15.0.0 || ^16.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN shamma No description
npm WARN shamma No repository field.
npm WARN shamma No license field.

in the code there is a several packages for dependencies, one of them is -->>

{
  "dependencies": {
    "@empirica/core": "1.0.0-rc.21",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "@types/react": "18.0.14",
    "@types/react-dom": "18.0.5",
    "@vitejs/plugin-react-refresh": "1.3.6",
    "autoprefixer": "10.4.7",
    "path": "0.12.7",
    "vite": "2.9.15",
    "vite-plugin-restart": "0.1.1",
    "vite-plugin-windicss": "1.8.4"
  },
  "name": "my-experiment-empirica-server",
  "private": true,
  "scripts": {
    "build": "vite build",
    "dev": "NODE_ENV=\"production\" vite",
    "serve": "vite preview"
  },
  "version": "0.0.0",
  "volta": {
    "node": "16.17.0",
    "npm": "8.15.0"
  }
}

CodePudding user response:

Delete the node_modules & package-lock.json and try npm install

or run npm audit fix

CodePudding user response:

Try this:

  1. Remove your node_modules folder (rm -rf node_modules)
  2. npm cache clean -f
  3. npm install
  • Related