webpack - 属性 类型 NodeRequire 上不存在上下文
webpack - Property context does not exist on type NodeRequire
我想使用:
require.context('../images/', true, /\.(png|ico|svg|jpg|gif)$/)
但我收到以下错误:
Property context does not exist on type NodeRequire
2018 年的解决方案:
只需为 webpack-env
安装类型
npm i @types/webpack-env -D
并在 tsconfig.json 中将其添加到 属性 类型中
示例:
{
"compilerOptions": {
"outDir": "./dist/",
"declaration": true,
"declarationDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es6",
"allowJs": false,
"types": [
"node",
"webpack-env" // here
]
},
"files": [
"src/index.ts"
],
"compileOnSave": false
}
我想使用:
require.context('../images/', true, /\.(png|ico|svg|jpg|gif)$/)
但我收到以下错误:
Property context does not exist on type NodeRequire
2018 年的解决方案:
只需为 webpack-env
npm i @types/webpack-env -D
并在 tsconfig.json 中将其添加到 属性 类型中 示例:
{
"compilerOptions": {
"outDir": "./dist/",
"declaration": true,
"declarationDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es6",
"allowJs": false,
"types": [
"node",
"webpack-env" // here
]
},
"files": [
"src/index.ts"
],
"compileOnSave": false
}