简体   繁体   English

反应故事书jest快照导致错误无法从'node.js'找到模块'../../package'

[英]react storybook jest snapshots leads to an error Cannot find module '../../package' from 'node.js'

I want to combine storybooks and jest snapshot testing, but I don't get it working. 我想结合故事书和开玩笑快照测试,但我没有让它工作。 As soon as I follow the doc and add the Snapshot.test.js, it leads to following error, when I run npm test. 一旦我按照文档添加Snapshot.test.js,当我运行npm test时,它会导致跟随错误。

FAIL ./Storyshots.test.js Test suite failed to run

Cannot find module '../../package' from 'node.js'

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)

  at Object.<anonymous> (node_modules/babel-core/lib/api/node.js:60:16)

anyone has a clue / hint if this is a failure of implementation or a bug? 任何人都有线索/提示,如果这是实施失败或错误? thnx a lot! thnx很多!

this is my jest configuration, it my gives a hint? 这是我的开玩笑配置,我给出了一个提示?

"jest": {
    "rootDir": "",
    "transform": {
      ".*": "<rootDir>/node_modules/babel-jest"
    },
    "moduleFileExtensions": [
      "js",
      "jsx"
    ],
    "collectCoverage": false,
    "collectCoverageFrom": [
      "**/*.{js,jsx}",
      "!**/node_modules/**",
      "!**/vendor/**"
    ],
    "coverageDirectory": "<rootDir>/coverage",
    "setupTestFrameworkScriptFile": "<rootDir>/jestSetup.js",
    "unmockedModulePathPatterns": [
      "<rootDir>/node_modules/react",
      "<rootDir>/node_modules/react-dom",
      "<rootDir>/node_modules/react-addons-test-utils",
      "moment",
      "jasmine-expect-jsx",
      "fbjs",
      "enzyme",
      "expect",
      "cheerio",
      "htmlparser2",
      "lodash",
      "domhandler",
      "object.assign",
      "define-properties",
      "function-bind",
      "object-keys",
      "object.values",
      "es-abstract"
    ]
  },

I had this same problem and my solution was add "json" into "moduleFileExtensions", just like this: 我有同样的问题,我的解决方案是将“json”添加到“moduleFileExtensions”中,就像这样:

...
"moduleFileExtensions": [
  "js",
  "jsx",
  "json"
],
...

Seems like the file 'package' was not a js[x] file, but a json one, and jest refused to load it. 好像文件'package'不是js [x]文件,而是json文件,而jest拒绝加载它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 REACT JEST错误无法从&#39;jest-expect.js&#39;中找到模块&#39;jest-matchers&#39; - REACT JEST error Cannot find module 'jest-matchers' from 'jest-expect.js' 如何解决 React 项目中的酶/Jest 错误“无法从 &#39;react-router.js&#39; 中找到模块 &#39;react&#39;” - How to solve an Enzyme/Jest error "Cannot find module 'react' from 'react-router.js'" in a React project Node.js:找不到模块 react-dom/server - Node.js: Cannot find module react-dom/server 如何修复 Node.js 错误:找不到模块“immer” - How to fix Node.js error: Cannot find module 'immer' Node.js 在 npm 启动时找不到模块错误 - Node.js Cannot Find Module error on npm start React Jest 无法从“node_modules/@mui/styled-engine/node/index.js”中找到模块“@emotion/styled” - React Jest Cannot find module '@emotion/styled' from 'node_modules/@mui/styled-engine/node/index.js' 玩笑失败 React 16 升级后无法从“ReactShallowRenderer.js”中找到模块“react/lib/React” - Jest fails Cannot find module 'react/lib/React' from 'ReactShallowRenderer.js' after React 16 upgrade 用酶和玩笑测试 React 给出错误无法从“index.js”中找到模块“@babel/polyfill/lib/noConflict” - Testing React with enzyme and jest giving error Cannot find module '@babel/polyfill/lib/noConflict' from 'index.js' 开玩笑:找不到模块“反应”和其他 node_modules - jest: Cannot find module 'react', and other node_modules 开玩笑测试:无法从'Link.react.js'中找到模块'../Link.react' - Jest test: Cannot find module '../Link.react' from 'Link.react.js'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM