Reputation: 1009
Webpack (specifically awesome-typescript-loader) fails to build my app because of the following error:
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
"devDependencies": {
" @types/node": "^7.0.22"
...
awesome-typescript-loader
is aware of my 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
"typeRoots": [
"node_modules/@types"
],
"types": [
"node",
"webpack"
],
declare module '*';
declare var require: any
Anything else I could try?
Upvotes: 3
Views: 6065
Reputation: 18055
I had solve this by adding a new webpack.d.ts
and adding below content to it..
declare var require: (filename: string) => any;
Upvotes: 2