[英]'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 install
和npm start
并且仍然得到相同的块。 (Also tried npm update
, npm install
and npm start
, still same bug). (也试过
npm update
, npm install
和npm 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.