gpt4 book ai didi

TypeScript 错误 "Cannot read property ' 导出“未定义”

转载 作者:行者123 更新时间:2023-12-02 11:00:49 27 4
gpt4 key购买 nike

我正在尝试使用 TypeScript 构建一个 Redux 中间件。这个功能

import { Middleware } from "redux"

function createMiddleware() {
return ({ dispatch, getState }) => next => action => {
if (Math.random() > 0.5) {
return next(action)
}

return next(action)
}
}

export const middleware: Middleware = createMiddleware()

产生一个 TypeScript 错误:
Typescript error: Cannot read property 'exports' of undefined

虽然当我删除 if block 时编译器没有提示。

我的 tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"noImplicitAny": false,
"skipLibCheck": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"jsx": "react",
"lib": ["dom", "es2015", "es2016"],
"baseUrl": "../src",
"exclude": [
"node_modules"
]
}
}

编辑 来自浏览器控制台的 Stacktrace
Uncaught Error: Module build failed: TypeError: Cannot read property 'exports' of undefined
at resolveName (..\node_modules\typescript\lib\typescript.js:24948:70)
at getResolvedSymbol (..\node_modules\typescript\lib\typescript.js:32549:67)
at checkIdentifier (..\node_modules\typescript\lib\typescript.js:33700:26)
at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38185:28)
at checkExpression (..\node_modules\typescript\lib\typescript.js:38165:42)
at checkNonNullExpression (..\node_modules\typescript\lib\typescript.js:35540:24)
at checkPropertyAccessExpressionOrQualifiedName (..\node_modules\typescript\lib\typescript.js:35587:24)
at checkPropertyAccessExpression (..\node_modules\typescript\lib\typescript.js:35554:20)
at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38208:28)
at checkExpression (..\node_modules\typescript\lib\typescript.js:38165:42)
at checkNonNullExpression (..\node_modules\typescript\lib\typescript.js:35540:24)
at resolveCallExpression (..\node_modules\typescript\lib\typescript.js:36556:28)
at resolveSignature (..\node_modules\typescript\lib\typescript.js:36786:28)
at getResolvedSignature (..\node_modules\typescript\lib\typescript.js:36809:26)
at checkCallExpression (..\node_modules\typescript\lib\typescript.js:36836:29)
at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38213:28)
at resolveName (..\node_modules\typescript\lib\typescript.js:24948:70)
at getResolvedSymbol (..\node_modules\typescript\lib\typescript.js:32549:67)
at checkIdentifier (..\node_modules\typescript\lib\typescript.js:33700:26)
at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38185:28)
at checkExpression (..\node_modules\typescript\lib\typescript.js:38165:42)
at checkNonNullExpression (..\node_modules\typescript\lib\typescript.js:35540:24)
at checkPropertyAccessExpressionOrQualifiedName (..\node_modules\typescript\lib\typescript.js:35587:24)
at checkPropertyAccessExpression (..\node_modules\typescript\lib\typescript.js:35554:20)
at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38208:28)
at checkExpression (..\node_modules\typescript\lib\typescript.js:38165:42)
at checkNonNullExpression (..\node_modules\typescript\lib\typescript.js:35540:24)
at resolveCallExpression (..\node_modules\typescript\lib\typescript.js:36556:28)
at resolveSignature (..\node_modules\typescript\lib\typescript.js:36786:28)
at getResolvedSignature (..\node_modules\typescript\lib\typescript.js:36809:26)
at checkCallExpression (..\node_modules\typescript\lib\typescript.js:36836:29)
at checkExpressionWorker (..\node_modules\typescript\lib\typescript.js:38213:28)
at Object../src/store/middleware.ts (http://localhost:8080/static/js/main.js:69038:7)
at __webpack_require__ (http://localhost:8080/static/js/main.js:660:30)

最佳答案

感谢 Martin,我发现这实际上是 Webpack 2 的问题。切换到 Webpack 1 为我解决了这个问题。

关于TypeScript 错误 "Cannot read property ' 导出“未定义”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41714708/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com