[英]'react' - After run npm start it gives ./src/index.js Module not found: Can't resolve 'react' in 'C:\Users\...\src' error
[英]'react' - After run npm start it gives./src/contentful.js Module not found: Can't resolve 'contenful' in 'C:\Users\..\my-blog\src'
我運行了 npm install,得到了節點模塊和包,但是當我運行 npm start 時出現這個錯誤:
./src/contentful.js
找不到模塊:無法解析“C:\\Users\\Dannis\\my-blog\\src”中的“contenful”
我試圖刪除package-json.lock
,然后運行npm install
和npm start
並且仍然得到相同的塊。 (也試過npm update
, npm install
和npm start
,仍然是同樣的錯誤)。
這是我的 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"
]
}
}
我嘗試安裝 react-router-dom、react-markdown 和 history,但出現此錯誤:
無法讀取未定義的屬性“匹配”。
有任何想法嗎?
@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'
}
./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 }
更新:剛剛運行了一個 npm 更新,現在我得到:
./src/contentful.js Line 1:16: 'contentful' 沒有定義 no-undef
當您在瀏覽器中運行它時,嘗試使用 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.