我创建了一个 index.js、index.html 和 package.json 文件,我想添加 express。当我在终端中编写“npm install express”时,出现以下错误。到目前为止,我尝试了“sudo npm install -g express”,完全删除节点和 npm 并重新安装。我还在这里解决了其他问题,但没有一个对我有用。无论我用 npm 写什么,我都会遇到同样的错误。(我使用的是 macOS)
你有什么建议吗?
这是我得到的错误:
Error: EROFS: read-only file system, mkdir '/npm'
TypeError: Cannot read property 'loaded' of undefined
at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97:27)
at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:78:20
at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22)
at /usr/local/lib/node_modules/npm/lib/npm.js:263:24
at /usr/local/lib/node_modules/npm/lib/config/core.js:81:7
at Array.forEach (<anonymous>)
at /usr/local/lib/node_modules/npm/lib/config/core.js:80:13
at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:171:20)
/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97
var doExit = npm.config.loaded ? npm.config.get('_exit') : true
^
TypeError: Cannot read property 'loaded' of undefined
at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97:27)
at …Run Code Online (Sandbox Code Playgroud) 我希望能够通过从 JSON 文件获取 URL 来显示本地文件夹中的图像。到目前为止我已经尝试过:
src={require(blog.imUrl)} src={blog.imgUrl} src={require( ${blog.imgUrl})}
当我使用 require 时遇到错误:
错误:找不到模块“../../images/safe-image.jpeg”
import { useHistory } from 'react-router-dom';
import { Col, Row, Container, Image } from 'react-bootstrap';
import blogArticles from './blog.json';
import './BlogCard.css';
export default function BlogCard() {
const history = useHistory();
function handleClick() {
history.push('/`${blog.id}`');
}
return blogArticles.map((blog) => {
return (
<Container key={blog.id} className="blogContainer">
<Row>
<Col xs={6} md={6} lg={8}>
<h3 className="blogTitle">{blog.title}</h3>
<span className="blogBody">{blog.body.substring(0, 250)}...</span>
<button onClick={handleClick} className="readMoreButton">
Read More
</button>
</Col>
<Col xs={4} md={4} lg={3} className="imageContainer"> …Run Code Online (Sandbox Code Playgroud)