[英]javascript import/require Error: Cannot find module '@react-select/monorepo' from '…/src/static/js/react_apps/utils'
I'm having issues importing a module not via NPM:我在导入不是通过 NPM 的模块时遇到问题:
I forked the repo and also tried a local install with no luck, so I tried installing via github.我分叉了 repo,还尝试了本地安装,但没有成功,所以我尝试通过 github 安装。
I've tried both using import as well as require as listed below.我已经尝试过使用 import 和 require ,如下所示。 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.有问题的文件位于
utils
文件夹中,这可能就是它在那里搜索 react-select 的原因。
import Select from "@react-select/monorepo";
const Select = require("@react-select/monorepo");
What does work (when installed via npm repository):什么工作(通过 npm 存储库安装时):
import Select from "react-select";
Package.json: Package.json:
"@react-select/monorepo": "github:kckaiwei/react-select#onMultiValueLabelClick",
Getting the following error when running browserify
:运行
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
It's not clear what you're trying to do, but since you said目前尚不清楚您要做什么,但是既然您说
I'm having issues importing a module not via NPM:
我在导入不是通过 NPM 的模块时遇到问题:
I forked the repo
我分叉了回购
I can argue you want to import in your project a locally changed version of react-select
.我可以说你想在你的项目中导入一个本地更改的
react-select
版本。
If that's actually what you want to do, you are looking for npm link .如果这实际上是您想要做的,那么您正在寻找npm 链接。
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.这不是理想的解决方案,但经过深思熟虑,我最终只是通过 NPM 为我的分支创建了一个单独的 package 进行安装,这确实有效,但需要维护这个分支,由于分叉,这无论如何都是必要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.