[英]ts-jest cannot run testing on imported ES6 modules
我在Typescript应用程序中使用了已编译的ES6库。 测试失败并显示错误
TypeError:无法读取未定义的属性“ PropTypes”
它抱怨的模块正在导入react
as
import React from 'react';
如果我将其更改为
import * as React from 'react';
然后它将编译并运行良好。 这是我的package.json
的jest
配置:
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js|jsx)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"verbose": true,
}
这是我的tsconfig.json
:
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true,
"preserveConstEnums": true,
"removeComments": true,
"noImplicitAny": false,
"moduleResolution": "node",
"noUnusedParameters": true
},
"include": [
"./src/**/*"
],
"filesGlob": [
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts",
"typings/index.d.ts"
]
}
我在这里搞砸了什么配置?
then it will compile and run fine.
这就是TypeScript的方法。 import * as React from "react"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.