[英]TS2304: Cannot find name 'require'
Webpack (specifically awesome-typescript-loader ) fails to build my app because of the following error: 由于以下错误,Webpack(特别是awesome- typescript -loader )无法构建我的应用程序:
ERROR in [at-loader] ./src/app/app.ts:6:13
TS2304: Cannot find name 'require'.
The associated code: 相关代码:
@Component({
name: 'App',
template: require('./app.template.pug') <---
})
export class AppComponent extends Vue {
}
There's a similiar question here which describes the exact same error, and I've tried various solutions mentioned in the answers, however with no success: 还有一个类似的问题在这里 ,它描述了完全相同的错误,我已经试过在答案中提到的各种解决方案,但是没有成功:
package.json
package.json
"devDependencies": {
" @types/node": "^7.0.22"
...
awesome-typescript-loader
is aware of my tsconfig.json
: awesome-typescript-loader
tsconfig.json
awesome-typescript-loader
知道我的tsconfig.json
: loader: 'awesome-typescript-loader',
options: {
configFileName: 'tsconfig.json',
useCache: config.build.useCaching
}
Types
aswell as type roots
have been declared in tsconfig.json
Types
以及type roots
已在tsconfig.json
声明 "typeRoots": [
"node_modules/@types"
],
"types": [
"node",
"webpack"
],
declare module '*';
declare var require: any
Anything else I could try? 还有什么我可以尝试的吗?
我通过添加一个新的webpack.d.ts
并在其中添加以下内容来解决这个问题。
declare var require: (filename: string) => any;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.