我正在使用带有webpack的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.
Variable 'global' must be of type 'global', but here has type 'Global'.
{
"compilerOptions": {
"module": "commonjs",
"rootDir": "./dev",
"outDir": "./src",
"alwaysStrict": true,
"baseUrl": "./",
"lib": ["es5", "es6", "dom"],
"typeRoots": [
"./node_modules/@types"
]
},
"include": [
"./dev/**/*",
"./node_modules/@types/*"
]
}
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(),
],
};
{
"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"
}
}
答案 0 :(得分:0)
您的代码中的某个地方或您依赖的库可能是您的cheerio-httpcli
declare var global: any;
由于某种原因打字稿编译器抱怨。您需要将其更改为。
declare var global: NodeJS.Global;
你的错误将消失,或者你可能会收到另一个错误,抱怨它可以找到NodeJS,因为它需要包含在node_modules中的tsconfig.json @types文件夹中;
"typeRoots": [
"node_modules/@types"
]