JavaScript - jest-haste-map:Haste 模块命名冲突:{{name}}

Kou*_*sha 12 javascript jestjs

当我运行时出现以下错误npm run test

jest-haste-map: Haste module naming collision: {{name}}
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/packages/some-package/templates/js/package.json
    * <rootDir>/packages/some-package/templates/ts/package.json
Run Code Online (Sandbox Code Playgroud)

我的jest.config样子

module.exports = {
  collectCoverage: true,
  setupFiles: ['<rootDir>/jest.setup.js'],
  preset: 'ts-jest',
  testEnvironment: 'jsdom',
  collectCoverageFrom: [
    '<rootDir>/packages/**/__tests__/**/*.ts',
    '!<rootDir>/packages/**/templates/**/*.ts',
  ],
  testMatch: [
    '<rootDir>/packages/**/*.test.ts'
  ],
  transform: {
    '^.+\\.js?$': '<rootDir>/node_modules/babel-jest'
  },
  testPathIgnorePatterns: [
    '/node_modules/',
  ],
  coveragePathIgnorePatterns: [
    '/node_modules/',
  ],
  projects: [
    '<rootDir>/packages/*/jest.config.js'
  ]
};
Run Code Online (Sandbox Code Playgroud)

不确定警告是什么,以及如何解决它。

小智 17

由于package.json存在于我的根目录和build目录中,我收到此警告。src我可以通过将以下内容添加到我的 package.json来指定我只希望 Jest 查找测试来摆脱它:

  "jest": {
    "roots": ["src"]
  }
Run Code Online (Sandbox Code Playgroud)