【发布时间】:2017-08-09 02:11:08
【问题描述】:
我在我的 Typescript 应用程序中使用已编译的 ES6 库。测试失败并出现错误
TypeError:无法读取未定义的属性“PropTypes”
它抱怨的模块将react 导入为
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"
]
}
我在这里搞砸了什么配置?
【问题讨论】:
标签: javascript reactjs typescript jestjs