我有一个与tsjest和Typescript一起使用的gatsby项目。在测试过程中,我得到了错误...
error TS5055: Cannot write file '/Users/Jeff/go/src/site/frontend/node_modules/gatsby/cache-dir/gatsby-browser-entry.js' because it would overwrite input file.
这似乎很简单,但是当我尝试将tsconfig设置为使用outDir
时,如链接所示,仍然出现错误。使它工作的唯一方法是设置noEmit: true
....
我的配置在下面
{
"compilerOptions": {
"target": "ESNEXT",
"module": "ESNext",
"lib": ["dom", "esnext"],
"allowJs": true,
"jsx": "react",
"outDir": "./dist/",
"rootDir": "./",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": ["./src/**/*", "./node_modules/gatsby/**/*"],
"exclude": ["./node_modules"]
}
jest.config.js
module.exports = {
setupTestFrameworkScriptFile: '<rootDir>/src/setupTests.ts',
verbose: true,
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
'typeface-roboto|\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js'
},
testPathIgnorePatterns: ['<rootDir>/.cache'], // ignore gatsby cache tests
globals: {
'ts-jest': {
enableTsDiagnostics: true
}
},
transform: {
'^.+\\.(jsx?|tsx?)$': 'ts-jest'
},
// the 'undoes' ignore of node modules to transpile defaults in gatsby to es5 which is needed in anything that imports something from gatsby
transformIgnorePatterns: ['<rootDir>/node_modules/(?!gatsby)'],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
};