gpt4 book ai didi

linux - gatsby 站点的 Jest watch 重启失败,fs/watchers 失败

转载 作者:行者123 更新时间:2023-12-03 10:00:17 25 4
gpt4 key购买 nike

我在 Gatsby 网站上工作。我有 test在我的 package.json设置为 "test": "jest --watch --no-cache", .大多数情况下,当我保存时, watch 工作没有问题。然而,偶尔,也许是语法错误,我的 watch 错误,失败并退出。我想解决这个问题,但不知道根据这个错误该往哪个方向发展。
我的 Jest 控制台输出如下:

Test Suites: 0 of 8 total
Tests: 0 total
Snapshots: 0 total
Time: 0 sinternal / fs / watchers.js: 173
throw error;
^

Error: ENOENT: no such file or directory, watch '/home/[USER]/backup/myGatsbySite/.cache/redux.bak'
at FSWatcher.start(internal / fs / watchers.js: 165: 26)
at Object.watch(fs.js: 1340: 11)
at NodeWatcher.watchdir(/home/[USER] / backup / myGatsbySite / node_modules / sane / src / node_watcher.js: 159: 22)
at NodeWatcher.<anonymous>(/home/[USER] / backup / myGatsbySite / node_modules / sane / src / node_watcher.js: 295: 18)
at FSReqCallback.oncomplete(fs.js: 170: 5) {
errno: -2,
syscall: 'watch',
code: 'ENOENT',
path: '/home/[USER]/backup/myGatsbySite/.cache/redux.bak',
filename: '/home/[USER]/backup/myGatsbySite/.cache/redux.bak'

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-starter-default@0.2.0 test: `jest --watch --no-cache`
npm ERR! Exit status 1

还有一个指向 npm 的链接我粘贴在下面的日志。
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli '/home/[USER]/.nvm/versions/node/v12.11.1/bin/node',
1 verbose cli '/home/[USER]/.nvm/versions/node/v12.11.1/bin/npm',
1 verbose cli 'run',
1 verbose cli 'test'
1 verbose cli ]
2 info using npm@6.11.3
3 info using node@v12.11.1
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle gatsby-starter-default@0.2.0~pretest: gatsby-starter-default@0.2.0
6 info lifecycle gatsby-starter-default@0.2.0~test: gatsby-starter-default@0.2.0
7 verbose lifecycle gatsby-starter-default@0.2.0~test: unsafe-perm in lifecycle true
8 verbose lifecycle gatsby-starter-default@0.2.0~test: PATH: /home/[USER]/.nvm/versions/node/v12.11.1/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/[USER]/backup/myGatsbySite/node_modules/.bin:/home/[USER]/.shopify-app-cli/bin/user:/home/[USER]/.nvm/versions/node/v12.11.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle gatsby-starter-default@0.2.0~test: CWD: /home/[USER]/backup/myGatsbySite
10 silly lifecycle gatsby-starter-default@0.2.0~test: Args: [ '-c', 'jest --watch --no-cache' ]
11 silly lifecycle gatsby-starter-default@0.2.0~test: Returned: code: 1 signal: null
12 info lifecycle gatsby-starter-default@0.2.0~test: Failed to exec test script
13 verbose stack Error: gatsby-starter-default@0.2.0 test: `jest --watch --no-cache`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/home/[USER]/.nvm/versions/node/v12.11.1/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:210:5)
13 verbose stack at ChildProcess.<anonymous> (/home/[USER]/.nvm/versions/node/v12.11.1/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:210:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid gatsby-starter-default@0.2.0
15 verbose cwd /home/[USER]/backup/myGatsbySite
16 verbose Linux 5.4.0-7642-generic
17 verbose argv "/home/[USER]/.nvm/versions/node/v12.11.1/bin/node" "/home/[USER]/.nvm/versions/node/v12.11.1/bin/npm" "run" "test"
18 verbose node v12.11.1
19 verbose npm v6.11.3
20 error code ELIFECYCLE
21 error errno 1
22 error gatsby-starter-default@0.2.0 test: `jest --watch --no-cache`
22 error Exit status 1
23 error Failed at the gatsby-starter-default@0.2.0 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

我的 jest.config :
module.exports = {
transform: {
"^.+\\.jsx?$": `<rootDir>/jest-preprocess.js`,
},
moduleNameMapper: {
".+\\.(css|styl|less|sass|scss)$": `identity-obj-proxy`,
".+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": `<rootDir>/__mocks__/file-mock.js`,
},
testPathIgnorePatterns: [`node_modules`, `.cache`, `public`],
transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`],
globals: {
__PATH_PREFIX__: ``,
},
testURL: `http://localhost`,
setupFiles: [`<rootDir>/loadershim.js`],
setupFilesAfterEnv: ["<rootDir>/setup-test-env.js"],
}
我真的不知道从哪里开始。欢迎提供解决问题的答案,但那些解释您阅读的这两个错误的哪一部分以便我可以自己解决问题的答案将特别受欢迎。

最佳答案

问题
运行时 jest —watch Jest 通过 fsevents 跟踪目录中的所有文件以进行更新.当它在目录中跟踪的项目被删除时,它会注意到更改但无法重新加载不再存在的文件,从而导致“找不到文件或目录错误”。
gatsby develop启动它会创建“.cache”目录——正如你所期望的那样,在开发过程中会不断修改。
我不完全确定确切的机制,但 Gatsby 可能会删除“.cache”目录中的 .bak 文件,而 Jest 可能会在发生这种情况时遇到“找不到文件”错误。
解决方案
配置 Jest 以忽略“.cache”目录。
例子

"jest": {
"testPathIgnorePatterns": [".cache"]
}
笔记
这是一个跟踪问题,可能已在最新版本的 Jest 中解决: https://github.com/facebook/jest/issues/8265

关于linux - gatsby 站点的 Jest watch 重启失败,fs/watchers 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64372125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com