变量'global'必须是"全局"类型,但此处 h 为类型 'Global'



我正在使用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

{
"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(),
],
};

包.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"
}
}

在你的代码或你依赖的库中的某个地方,你可能在你拥有的那个cheerio-httpcli中

declare var global: any;

出于某种原因,打字稿编译器抱怨。您需要将其更改为。

declare var global: NodeJS.Global;

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

"typeRoots": [
"node_modules/@types"
]

最新更新