javascript import/require Error: Cannot find module '@react-select/monorepo' from '.../src/static/js/react_apps/utils'

Viewed 260

I'm having issues importing a module not via NPM:

I forked the repo and also tried a local install with no luck, so I tried installing via github.

I've tried both using import as well as require as listed below. Not quite sure why it keeps insisting to look in locally

The file that's having issue is in the utils folder, which is probably why it's searching for react-select there.

import Select from "@react-select/monorepo";
const Select = require("@react-select/monorepo");

What does work (when installed via npm repository):

import Select from "react-select";

Package.json:

    "@react-select/monorepo": "github:kckaiwei/react-select#onMultiValueLabelClick",

Getting the following error when running browserify:

Error: Cannot find module '@react-select/monorepo' from '.../src/static/js/react_apps/utils'
    at .../node_modules/browser-resolve/node_modules/resolve/lib/async.js:46:17
    at process (.../node_modules/browser-resolve/node_modules/resolve/lib/async.js:173:43)
    at ondir (.../node_modules/browser-resolve/node_modules/resolve/lib/async.js:188:17)
    at load (.../node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
    at onex (.../node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
    at .../node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
    at FSReqCallback.oncomplete (fs.js:165:21)

Directory structure looks like:

project --- src --- static
       |
       |--- node_modules --- @react-select --- monorepo

2 Answers

It's not clear what you're trying to do, but since you said

I'm having issues importing a module not via NPM:

I forked the repo

I can argue you want to import in your project a locally changed version of react-select.

If that's actually what you want to do, you are looking for npm link.

  1. git checkout forked_repos
  2. cd forked_repos_directory
  3. npm link
  4. cd your_project_directory
  5. npm link react-select

That's all, you neither need to change the import statement.

Hope this helps.

Not the ideal solution to this, but after much deliberating, I ended up just installing via NPM by creating a separate package for my branch, which does work but requires maintaining this branch, which was going to be necessary anyways due to forking.

Related