简体   繁体   English

无法解析模块“反应”的路径。 (导入/未解决)

[英]Unable to resolve path to module 'react'. (import/no-unresolved)

Seems like i am missing something here, it should work without errors but eslint keeps throwing the following:好像我在这里遗漏了一些东西,它应该可以正常工作但eslint不断抛出以下内容:

Unable to resolve path to module 'react'.无法解析模块“反应”的路径。 (import/no-unresolved) (导入/未解决)

Missing file extension for "react" (import/extensions)缺少“反应”的文件扩展名(导入/扩展)

when trying to import React from 'react'尝试import React from 'react'

here is some debug info:这是一些调试信息:

package.json package.json

{
  "dependencies": {},
  "devDependencies": {
    "react": "16.3.2",
    "react-dom": "16.3.2",
    "@storybook/addon-actions": "^3.4.2",
    "@storybook/addon-links": "^3.4.2",
    "@storybook/addons": "^3.4.2",
    "@storybook/react": "^3.4.2",
    "babel-core": "^6.26.3",
    "babel-eslint": "^8.2.3",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "babel-runtime": "^6.26.0",
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0"
  }
}

.eslintrc .eslintrc

{
  "parser": "babel-eslint",
  "extends": ["airbnb", "prettier"],
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  }
}

.babelrc .babelrc

{
  "presets": ["env", "react"]
}

editor : atom v1.26.1编辑:atom v1.26.1

Thanks.谢谢。

If you're using React Native it may help to add .native.js as an allowed extension in your .eslintrc file.如果你使用 React Native,在你的.eslintrc文件中添加.native.js作为允许的扩展名可能会有所帮助。
Also, if you're using Typescript then .ts and .tsx will help too.此外,如果您使用的是 Typescript,那么.ts.tsx也会有所帮助。

"settings": {
  "import/resolver": {
    "node": {
      "extensions": [".ts", ".tsx", ".native.js"]
    }
  }
}

I think it complains because react should be in dependencies :我认为它会抱怨,因为react应该dependencies

{
  "dependencies": {
    "react": "16.3.2",
    "react-dom": "16.3.2",
  },
  "devDependencies": {
    "@storybook/addon-actions": "^3.4.2",
    "@storybook/addon-links": "^3.4.2",
    "@storybook/addons": "^3.4.2",
    "@storybook/react": "^3.4.2",
    "babel-core": "^6.26.3",
    "babel-eslint": "^8.2.3",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "babel-runtime": "^6.26.0",
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0"
  }
}

I installed react and react-dom using npm i -E react react-dom trying to install the exact version which didn't install it correctly.我使用npm i -E react react-dom安装了reactreact-dom尝试安装未正确安装的确切版本。

npm i react react-dom -D solved the problem. npm i react react-dom -D解决了这个问题。

Just comment out the import and run.只需注释掉导入并运行即可。 Then again remove the comments.然后再次删除评论。 It worked for me.它对我有用。

I have experience with the same problem.我有同样问题的经验。

In my case, this error appear because I pull new update from the remote repository and it's bring new dependencies.就我而言,出现此错误是因为我从远程存储库中提取了新更新并带来了新的依赖项。

To solve this, I just install that dependencies with npm install为了解决这个问题,我只需使用npm install安装该依赖项

我遇到了一些问题,我从项目中删除了 nodo_modules 目录并运行 yarn install / npm install

This also happened to me.这也发生在我身上。 In my case, it was because I was running npm version 6, but a team member had installed a new library via npm version 7. Version 7 uses a new version for the lock file format.就我而言,这是因为我运行的是npm版本 6,但是团队成员通过npm版本 7 安装了一个新库。版本 7 使用新版本的锁文件格式。

Our solution was to make sure everyone was running the same npm version so that our package-lock.json files would be consistent.我们的解决方案是确保每个人都运行相同的npm版本,以便我们的package-lock.json文件保持一致。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 tsconfig 中的 eslint + typescript + 路径:ESLint:无法解析模块“@components/some-module”的路径。(import/no-unresolved) - eslint + typescript + path in tsconfig: ESLint: Unable to resolve path to module '@components/some-module'.(import/no-unresolved) React 测试库自定义设置导入 test-utils:未安装模块。 无法解析路径 - React Testing library custom setup import test-utils: module not installed. Unable to resolve path eslint 在声明文件上抛出 import/no-unresolved 错误 - eslint throwing import/no-unresolved error on declaration files 如何从导入“react”中删除未解决的 ESlint 错误 - How to remove ESlint error no-unresolved from importing 'react' 无法在React本机应用程序中解析模块'./package.json'的路径 - Unable to resolve path to module './package.json' in React native application 无法解析模块“react-native-screens”(ESLint)的路径 - Unable to resolve path to module 'react-native-screens' (ESLint) React Native (Typescript) 绝对路径无法解析模块 - React Native (Typescript) Absolute path unable to resolve module React native Typescript 路径别名无法解析模块 - React native Typescript path alias unable to resolve module React Native:无法解析模块 - React Native: Unable to Resolve Module 反应:无法在我自己的打字稿中解析模块和智能感知的路径,反应模块不起作用 - React:Unable to resolve path to module and intellisense in my own typescript react moudle does not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM