简体   繁体   English

'react' - 运行 npm start 后,它给出 ./src/contentful.js 找不到模块:无法解析 'C:\\Users\\..\\my-blog\\src' 中的 'contenful'

[英]'react' - After run npm start it gives./src/contentful.js Module not found: Can't resolve 'contenful' in 'C:\Users\..\my-blog\src'

I ran npm install, got the node modules and packages but when I run npm start I get this error:我运行了 npm install,得到了节点模块和包,但是当我运行 npm start 时出现这个错误:

./src/contentful.js ./src/contentful.js
Module not found: Can't resolve 'contenful' in 'C:\\Users\\Dannis\\my-blog\\src'找不到模块:无法解析“C:\\Users\\Dannis\\my-blog\\src”中的“contenful”

I tried to remove package-json.lock , run npm install and npm start afterward and still got the same block.我试图删除package-json.lock ,然后运行npm installnpm start并且仍然得到相同的块。 (Also tried npm update , npm install and npm start , still same bug). (也试过npm updatenpm installnpm start ,仍然是同样的错误)。

This is how my package.json looks like:这是我的 package.json 的样子:

{
  "name": "my-blog",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "contentful": "^7.13.1",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.4.0",
    "touch": "^3.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I tried to install react-router-dom, react-markdown and history and I get this error:我尝试安装 react-router-dom、react-markdown 和 history,但出现此错误:

Cannot read property 'match' of undefined.无法读取未定义的属性“匹配”。

Any ideas?有任何想法吗?

@user8555937 i ran npm version got this: @user8555937 我运行 npm 版本得到了这个:

{ 
'my-blog': '0.1.0', 
npm: '6.13.7', 
ares: '1.15.0', 
brotli: '1.0.7', 
cldr: '35.1', 
http_parser: '2.9.3', 
icu: '64.2', 
llhttp: '2.0.4', 
modules: '72', 
napi: '5', 
nghttp2: '1.40.0', 
node: '12.16.0', 
openssl: '1.1.1d',
tz: '2019c', 
unicode: '12.1', 
uv: '1.34.0', 
v8: '7.8.279.23-node.31', 
zlib: '1.2.11' 
}

@PedroMutter code for ./src/contentful.js: ./src/contentful.js 的@PedroMutter 代码:

const client = require('contentful').createClient({
  space: 'urer2vtwz5u1',
  accessToken: 'H31gCjOrReWAIbKiBWwBCtYF0_iw5kSVjZxh1FyHzNk'
})

const getBlogPosts = () => client.getEntries().then(response => response.items)

const getSinglePost = slug =>
  client
    .getEntries({
      'fields.slug': slug,
      content_type: 'blogPost'
    })
    .then(response => response.items)

export { getBlogPosts, getSinglePost }

UPDATE: just ran an npm update and now I get:更新:刚刚运行了一个 npm 更新,现在我得到:

./src/contentful.js Line 1:16: 'contentful' is not defined no-undef ./src/contentful.js Line 1:16: 'contentful' 没有定义 no-undef

As you are running it in a browser, try to import the contentful library using es6 import , you are mixing it with Commonjs :当您在浏览器中运行它时,尝试使用 es6 import contentful库,您将它与Commonjs混合:

import * as contentful from 'contentful';


const client = contentful.createClient({
  space: 'urer2vtwz5u1',
  accessToken: 'H31gCjOrReWAIbKiBWwBCtYF0_iw5kSVjZxh1FyHzNk'
})

const getBlogPosts = () => client.getEntries().then(response => response.items)

const getSinglePost = slug =>
  client
    .getEntries({
      'fields.slug': slug,
      content_type: 'blogPost'
    })
    .then(response => response.items)

export { getBlogPosts, getSinglePost }

暂无
暂无

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

相关问题 'react' - 运行 npm start 后,它给出 ./src/index.js Module not found: Can't resolve 'react' in 'C:\\Users\\...\\src' 错误 - 'react' - After run npm start it gives ./src/index.js Module not found: Can't resolve 'react' in 'C:\Users\...\src' error ./src/index.js 找不到模块:无法解析“c:\users\.....”中的“react-dom/client” - ./src/index.js Module not found: Can't resolve 'react-dom/client' in "c:\users\....." 如何解决 /src/index.js 未找到模块:无法解析 'C:\Users\hp\weather\src' 中的 './serviceWorker' - how to resolve /src/index.js Module not found: Can't resolve './serviceWorker' in 'C:\Users\hp\weather\src' 未找到模块:无法解析“C:\Users\Mohammad\Desktop\Chat-System\src\components”中的“..src/firebase.js” - Module not found: Can't resolve '..src/firebase.js' in 'C:\Users\Mohammad\Desktop\Chat-System\src\components' 未找到模块:无法解析“C:\Users\USER\auth_form_react\src”中的“firebaseui” - Module not found: Can't resolve 'firebaseui' in 'C:\Users\USER\auth_form_react\src' 找不到模块:无法解析“C:\\Users\\USER\\Desktop\\test\\src”中的“react” - Module not found: Can't resolve 'react' in 'C:\Users\USER\Desktop\test\src' [React Webpack]:找不到模块:错误:无法解析 'C:\Users\...' 中的 'src/views/UserList' - [React Webpack]: Module not found: Error: Can't resolve 'src/views/UserList' in 'C:\Users\…' 找不到模块:无法解析“C:\Users\user\Desktop\react-challenge\sample\src”中的“./App” - Module not found : Can't resolve './App' in 'C:\Users\user\Desktop\react-challenge\sample\src' ./src/Firebase.js 模块未找到:无法解析“C:\\Users\\HP\\Desktop\\React\\clone\\disney-plus-clone\\src”中的“firebase” - ./src/Firebase.js Module not found: Can't resolve 'firebase' in 'C:\Users\HP\Desktop\React\clones\disney-plus-clone\src' 如何修复“./src/index.js Module not found: Can't resolve 'loadash” in my react app? - How to fix "./src/index.js Module not found: Can't resolve 'loadash" in my react app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM