【问题标题】:Jest not updating in react and conflicting with jest in my node,js serverJest 在我的节点、js 服务器中没有更新反应并与 jest 冲突
【发布时间】:2021-03-19 23:54:56
【问题描述】:

我的应用程序没有运行我收到一个很长的错误 - 下面是一个摘要(完整的错误在底部)。如果我从 node.js 中删除 jest,则会出现错误并且我的应用程序会运行(但显然 jest 在我的服务器上不起作用)。


...The react-scripts package provided by Create React App requires a dependency:

  "babel-jest": "^24.9.0"...

在查看 react 应用时,我发现 babel 的版本很旧。我还使用 create-react-app 创建了一个全新的 react 应用程序,并且可以看到当我这样做时 babel-jest(以及许多 jest 文件)大约是 26 版本号。

babel-jest 版本号

my React App my node.js server a new app using create-react-app
24.9.0 26.6.0 26.6.0

看来我的错误是因为 create react app 中的 jest 版本已过期导致问题。

我该如何解决这个问题?如何更新 create-react-app 中的包? 我以为他们在我重新运行 npm init 时更新了??

我尝试过的

我删除了 node_modeuls 和 package.json.lock 并重新安装,还是一样

设置文件

我的设置 我的文件夹结构是这样的

./
./client  (react client app)
./client/package.json
./client/node_modules
package.json
node.modules
./server   (node.js api app)
./server/package.json
my jest is running from the ./package.json file.

代码设置

./package.json

{
    "name": "Infoshot",
    "version": "0.0.4",
    "description": "Research Tool",
    "main": "cd ./server && server.js",
    "scripts": {
        "start": "cd ./server && node server.js",
        "server": "cd ./server && nodemon server.js",
        "client": "npm start --prefix ./client/",
        "clientinstall": "npm install --prefix client",
        "dev": "concurrently \"npm run server\"  \"npm run client\"",
        "heroku-postbuild": "cd ./client && NPM_CONFIG_PRODUCTION=false npm install  && CI= npm run build",
        "compile-saas": "node-sass ./client/src/scss/a_main.scss ./server/nodeClient/public/css/main.css -w",
        "test": "jest",
        "test:watch": "npm run test -- --watch"
    },
    "jest": {
        "testEnvironment": "node",
        "testPathIgnorePatterns": [
            "./node_modules"
        ]
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "axios": "^0.21.0",
        "bcryptjs": "^2.4.3",
        "config": "^3.2.2",
        "dotenv": "^8.2.0",
        "ejs": "^3.1.5",
        "enzyme": "^3.11.0",
        "express": "^4.17.1",
        "express-validator": "^6.2.0",
        "ijavascript": "^5.2.0",
        "jest": "^26.6.3",
        "jsonwebtoken": "^8.5.1",
        "mongoose": "^5.7.0",
        "nodemailer": "^6.4.14",
        "nodemailer-sendgrid": "^1.0.3"
    },
    "devDependencies": {
        "concurrently": "^4.1.2",
        "node-sass": "^5.0.0",
        "nodemon": "^1.19.2"
    }
}

删除.test.json

describe.only('DELETE TEST: getDocument', () => {
    test('Say Hi', async () => {
        const bum = 'bum';
        expect(bum).toBe(bum);
    });
});

./client/package.json

正如我之前所说,我认为这无关紧要,因为我从 ./server 使用 npm run jest:watch 运行 jest 时不会运行它

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.19.0",
    "config": "^3.3.2",
    "dotenv": "^8.2.0",
    "enzyme-adapter-react-16": "^1.15.3",
    "node-sass": "^4.14.1",
    "react": "^16.9.0",
    "react-beautiful-dnd": "^13.0.0",
    "react-dom": "^16.9.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "^3.4.4",
    "react-transition-group": "^4.3.0",
    "serve": "^11.3.2",
    "styled-components": "^5.1.1",
    "uuid": "^3.3.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "previewProd": "react-scripts build && serve"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/components/documentEditor/*.js",
      "<rootDir>/server/",
      "!<rootDir>/node_modules/",
      "!<rootDir>/src/index.js",
      "!<rootDir>/src/registerServiceWorker.js"
    ]

完整的错误信息

^C


[0] npm ERR! code ELIFECYCLE                                                                     
[0] npm ERR! errno 130
[0] npm ERR! Infoshot@0.0.4 server: `cd ./server && nodemon server.js`
[0] npm ERR! Exit status 130
[0] npm ERR! 
[0] npm ERR! Failed at the Infoshot@0.0.4 server script.
[0] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[0] npm run server exited with code SIGINT
 ✘ bob@TDI-MacBook-Air  ~/Documents/repoActive/infoshot   develop  npm run dev

> Infoshot@0.0.4 dev /Users/bob/Documents/repoActive/infoshot
> concurrently "npm run server"  "npm run client"

[0] 
[0] > Infoshot@0.0.4 server /Users/bob/Documents/repoActive/infoshot
[0] > cd ./server && nodemon server.js
[0] 

> Infoshot@0.0.4 client /Users/bob/Documents/repoActive/infoshot
> npm start --prefix ./client/

[0] [nodemon] 1.19.4
[0] [nodemon] to restart at any time, enter `rs`
[0] [nodemon] watching dir(s): *.*
[0] [nodemon] watching extensions: js,mjs,json
[0] [nodemon] starting `node server.js`

> client@0.1.0 start /Users/bob/Documents/repoActive/infoshot/client
> react-scripts start


There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "babel-jest": "^24.9.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:

  /Users/bob/Documents/repoActive/infoshot/node_modules/babel-jest (version: 26.6.3) 

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if /Users/bob/Documents/repoActive/infoshot/node_modules/babel-jest is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls babel-jest in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed babel-jest.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the client@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bob/.npm/_logs/2020-12-08T08_43_14_491Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Infoshot@0.0.4 client: `npm start --prefix ./client/`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the Infoshot@0.0.4 client script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bob/.npm/_logs/2020-12-08T08_43_14_528Z-debug.log
npm run client exited with code 1
[0] -------------------------------
[0] Server started on Port: 5000
[0] (node:90252) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
[0] MongoDb Connected .......

【问题讨论】:

    标签: node.js reactjs jestjs package.json


    【解决方案1】:

    我想通了

    我需要从 ./ 安装(服务器安装)中删除 jest,然后安装旧版本的 jest,使其与 react 版本匹配

    npm install angular@6.2.1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      • 1970-01-01
      • 2020-07-04
      • 2020-08-05
      • 2018-01-29
      • 1970-01-01
      • 2019-10-04
      相关资源
      最近更新 更多