Переменная 'global' должна иметь тип 'global', но здесь h как тип 'Global' - PullRequest
0 голосов
/ 02 мая 2018

Я использую GoogleAppsScript с веб-пакетом для комплектации.
Когда я пытаюсь импортировать cheerio-httpcli, я получаю сообщение об ошибке.
Не могли бы вы сказать мне, как исправить эту ошибку?

Ошибка:

ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:102:13 TS2403: Subsequent variable declarations must have the same type.<br> Variable 'global' must be of type 'global', but here has type 'Global'.

tsconfig.json

{
  "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

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

{
  "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"
  }
}

1 Ответ

0 голосов
/ 12 июня 2018

Где-то в вашем коде или библиотеках, от которых вы зависите, вероятно, в том cheerio-httpcli, который у вас есть

declare var global: any;

На что по какой-то причине компилятор машинописи жалуется. Вам нужно изменить это на.

declare var global: NodeJS.Global;

И ваша ошибка исчезнет, ​​или вы можете получить другую ошибку с жалобой на то, что он может найти NodeJS, для которого вам нужно уйти, вам нужно включить его в папку tsconfig.json @types в node_modules;

"typeRoots": [
  "node_modules/@types"
]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...