首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >变量'global‘的类型必须是'global',但这里h的类型是'Global’

变量'global‘的类型必须是'global',但这里h的类型是'Global’
EN

Stack Overflow用户
提问于 2018-05-02 22:53:50
回答 1查看 2K关注 0票数 0

我正在使用GoogleAppsScript和webpack来捆绑。

当我尝试导入cheerio-httpcli时,我得到一个错误。

你能告诉我如何修复这个错误吗?

错误:

ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:102:13 TS2403: Subsequent variable declarations must have the same type.

Variable 'global' must be of type 'global', but here has type 'Global'.

tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "module": "commonjs",
    "rootDir": "./dev",
    "outDir": "./src",
    "alwaysStrict": true,
    "baseUrl": "./",
        "lib": ["es5", "es6", "dom"],
        "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "include": [
    "./dev/**/*",
        "./node_modules/@types/*"
  ]
}

webpack.config.js

代码语言:javascript
复制
const GasPlugin = require('gas-webpack-plugin');
const es3ifyPlugin = require('es3ify-webpack-plugin');

module.exports = {
  entry: './dev/index.ts',
  output: {
    filename: 'bundle.js',
    path: __dirname + '/src',
  },
  resolve: {
    extensions: ['.ts'],
  },
  module: {
    rules: [
      { test: /\.ts?$/, loader: 'awesome-typescript-loader' },
    ],
  },
  plugins: [
    new GasPlugin(),
    new es3ifyPlugin(),
  ],
};

package.json

代码语言:javascript
复制
{
  "name": "searchfrombigcamera",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "lint": "tslint -c tslint.json 'dev/**/*.ts'",
    "upload": "gapps upload",
    "watch": "watch 'npm run build && npm run upload' dev/",
    "build": "webpack"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/google-apps-script": "^0.0.14",
    "awesome-typescript-loader": "^3.2.3",
    "es3ify-webpack-plugin": "^0.0.1",
    "gas-webpack-plugin": "^0.2.1",
    "tslint": "^5.7.0",
    "typescript": "^2.5.2",
    "watch": "^1.0.2",
    "webpack": "^3.5.6"
  },
  "dependencies": {
    "@types/request": "^2.47.0",
    "cheerio-httpcli": "^0.7.3",
    "jsdom": "^11.10.0",
    "path": "^0.12.7",
    "request": "^2.85.0",
    "selenium-webdriver": "^4.0.0-alpha.1"
  }
}
EN

回答 1

Stack Overflow用户

发布于 2018-06-12 13:37:11

在您的代码中或您所依赖的库中的某处,可能在您拥有的cheerio httpcli中

代码语言:javascript
复制
declare var global: any;

由于某种原因,typescript编译器会抱怨。您需要将其更改为。

代码语言:javascript
复制
declare var global: NodeJS.Global;

你的错误将会消失,或者你可能会收到另一个错误,抱怨它可以找到你需要包含在node_modules中的tsconfig.json @types文件夹中的NodeJS;

代码语言:javascript
复制
"typeRoots": [
  "node_modules/@types"
]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50137622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档