【问题标题】:webpack - Property context does not exist on type NodeRequirewebpack - NodeRequire 类型上不存在属性上下文
【发布时间】:2018-08-02 18:58:09
【问题描述】:

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

但我收到以下错误:

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

【问题讨论】:

    标签: typescript webpack webpack-3


    【解决方案1】:

    2018 年的解决方案:

    只需安装 webpack-env 的类型

    npm i @types/webpack-env -D
    

    【讨论】:

      【解决方案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" // here
          ]
        },
        "files": [
          "src/index.ts"
        ],
        "compileOnSave": false
      }
      

      【讨论】:

        猜你喜欢
        • 2017-06-06
        • 1970-01-01
        • 2021-01-09
        • 2021-07-10
        • 2021-05-29
        • 2021-06-18
        • 2020-10-07
        • 2017-07-02
        相关资源
        最近更新 更多