webpack - NodeRequire类型上不存在属性上下文

时间:2018-02-22 19:25:28

标签: typescript webpack webpack-3

我想用: require.context('../images/', true, /\.(png|ico|svg|jpg|gif)$/)

但是我收到以下错误:

  

NodeRequire类型

上不存在属性上下文

2 个答案:

答案 0 :(得分:9)

只需安装ValueTask

的输入法
webpack-env

答案 1 :(得分:2)

并在 tsconfig.json 中将其添加到 types 属性中 例子:

 {
  "compilerOptions": {
    "outDir": "./dist/",
    "declaration": true,
    "declarationDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": false,
    "module": "commonjs",
    "target": "es6",
    "allowJs": false,
    "types": [
      "node",
      "webpack-env"
    ]
  },
  "files": [
    "src/index.ts"
  ],
  "compileOnSave": false
}