简体   繁体   English

javascript import/require 错误:无法从“…/src/static/js/react_apps/utils”中找到模块“@react-select/monorepo”

[英]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 链接

  1. git checkout forked_repos git 结帐 forked_repos
  2. cd forked_repos_directory cd forked_repos_directory
  3. npm link npm链接
  4. cd your_project_directory cd your_project_directory
  5. npm link react-select 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.

相关问题 反应并要求:错误:找不到模块“。” - React & require: Error: Cannot find module “.” JavaScript on Next.js 和 React 导入错误“无法解析模块'../utils/makeId'.eslintimport/no-unresolved 的路径” - JavaScript on Next.js and React import error "Unable to resolve path to module '../utils/makeId'.eslintimport/no-unresolved" 错误:找不到模块“react-dev-utils/inquirer” - Error: Cannot find module 'react-dev-utils/inquirer' 错误:找不到模块“react-dom/test-utils” - Error: Cannot find module 'react-dom/test-utils' 错误:找不到模块“ react-dev-utils / ignoredFiles” - Error: Cannot find module 'react-dev-utils/ignoredFiles' Vue.js 使用 src=require() 时来自 webpack 的错误“找不到模块 './undefined'” - Vue.js Error “Cannot find module './undefined'” from webpack when using src=require() 找不到模块 React require - Cannot find module React require 如何使用 React 和 Babel 从 React-Select CDN 导入? - How to import from React-Select CDN with React and Babel? 流星/反应:ReferenceError:未定义require /错误:找不到模块 - Meteor/React : ReferenceError: require is not defined / Error: Cannot find module 找不到模块“react-select/async”的声明文件 - Could not find a declaration file for module 'react-select/async'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM