如何求解参考:原始人未在fs.js:47:5定义?以前的解决方案对我不起作用

发布于 2025-02-10 12:36:51 字数 3536 浏览 0 评论 0原文

我是React的新手,我想运行JSON-Server,当我运行NPM Run Server时。我遇到了我尝试使用其他应用程序显示的先前建议来解决的错误

 fs.js:47        
} = primordials;
    ^

ReferenceError: primordials is not defined
    at fs.js:47:5
    at req_ (D:\Mysite-react\mysite\node_modules\natives\index.js:143:24)
    at Object.req [as require] (D:\Mysite-react\mysite\node_modules\natives\index.js:55:10)
    at Object.<anonymous> (D:\Mysite-react\mysite\node_modules\configstore\node_modules\graceful-fs\fs.js:1:37)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)

,但没有一个可行。 我创建了一个带有以下内容的npm-shrinkwrap.json文件: {“ depentencies”:{“ Graceful-fs”:{“ version”:“ 4.2.2”}}}}}并删除Node_modules文件夹,然后运行NPM npm install and code> and code>和我安装了Gulp 4。我的节点版本是v16.15.0。 i什至安装npm install 但这并不能解决我的问题。 我的poffage.json文件是

        {
  "name": "mysite",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fancyapps/ui": "^4.0.27",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.2.0",
    "@testing-library/user-event": "^13.5.0",
    "babel-preset-es2015": "^6.24.1",
    "bootstrap": "^5.1.3",
    "font-awesome": "^4.7.0",
    "formik": "^2.2.9",
    "gulp-v4": "^4.0.0-alpha.5",
    "json-server": "^0.4.2",
    "mixitup": "^3.3.1",
    "react": "^18.1.0",
    "react-animated-cursor": "^2.4.0",
    "react-bootstrap": "^2.4.0",
    "react-dom": "^18.1.0",
    "react-owl-carousel": "^2.3.3",
    "react-progressbar.js": "^0.1.2",
    "react-router-bootstrap": "^0.26.1",
    "react-router-dom": "^6.3.0",
    "react-scripts": "^2.1.3",
    "react-transition-group": "^1.2.1",
    "typed.js": "^2.0.12",
    "web-vitals": "^2.1.4",
    "yup": "^0.32.11"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "server": "json-server --watch mysite.json --port 8000",
    "type": "module",
    "dev": "nodemon ./bin/www"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.17.12",
    "@babel/plugin-syntax-jsx": "^7.17.12",
    "@babel/preset-react": "^7.17.12",
    "nodemon": "^2.0.16"
  }
}

在安装npm i Gulp -v4 -force之后,当我运行Gulp -v时,我有以下错误

gulp : The term 'gulp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ gulp -v
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (gulp:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I am new with react and I want to run json-server and when I run npm run server. I got this error

 fs.js:47        
} = primordials;
    ^

ReferenceError: primordials is not defined
    at fs.js:47:5
    at req_ (D:\Mysite-react\mysite\node_modules\natives\index.js:143:24)
    at Object.req [as require] (D:\Mysite-react\mysite\node_modules\natives\index.js:55:10)
    at Object.<anonymous> (D:\Mysite-react\mysite\node_modules\configstore\node_modules\graceful-fs\fs.js:1:37)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)

I tried to solve using the previous suggestions shown for other applications, but none are working.
I created an npm-shrinkwrap.json file with the following contents:
{ "dependencies": { "graceful-fs": { "version": "4.2.2" } } } and delete the node_modules folder, then Run npm install and I install Gulp 4. my node version is v16.15.0 . I even install npm install [email protected] but it did n't solve my problem.
my package.json file is

        {
  "name": "mysite",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fancyapps/ui": "^4.0.27",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.2.0",
    "@testing-library/user-event": "^13.5.0",
    "babel-preset-es2015": "^6.24.1",
    "bootstrap": "^5.1.3",
    "font-awesome": "^4.7.0",
    "formik": "^2.2.9",
    "gulp-v4": "^4.0.0-alpha.5",
    "json-server": "^0.4.2",
    "mixitup": "^3.3.1",
    "react": "^18.1.0",
    "react-animated-cursor": "^2.4.0",
    "react-bootstrap": "^2.4.0",
    "react-dom": "^18.1.0",
    "react-owl-carousel": "^2.3.3",
    "react-progressbar.js": "^0.1.2",
    "react-router-bootstrap": "^0.26.1",
    "react-router-dom": "^6.3.0",
    "react-scripts": "^2.1.3",
    "react-transition-group": "^1.2.1",
    "typed.js": "^2.0.12",
    "web-vitals": "^2.1.4",
    "yup": "^0.32.11"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "server": "json-server --watch mysite.json --port 8000",
    "type": "module",
    "dev": "nodemon ./bin/www"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.17.12",
    "@babel/plugin-syntax-jsx": "^7.17.12",
    "@babel/preset-react": "^7.17.12",
    "nodemon": "^2.0.16"
  }
}

after I installed npm i gulp-v4 --force , when I run gulp -v I have the following error

gulp : The term 'gulp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ gulp -v
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (gulp:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文