gpt4 book ai didi

node.js - Node 将 url 和查询字符串类型导入 TypeScript 应用程序

转载 作者:行者123 更新时间:2023-12-04 13:59:36 24 4
gpt4 key购买 nike

我想导入 urlquerystring TypeScript 应用程序中的 Node 模块。

import url from 'url';
import querystring from 'querystring';

但是我收到了休耕警告,而且我没有从中打字。

[ts] Could not find a declaration file for module 'url'. '.../node_modules/url/url.js' implicitly has an 'any' type. Try npm install @types/url if it exists or add a new declaration (.d.ts) file containing declare module 'url'; [7016]



我知道 urlquerystring是 Node 模块。我已安装 "@types/node": "^10.12.9",但它并没有解决来自警告的打字问题。

我应该怎么做才能从中打字?

信息:我不是使用 Vue CLI 的前端应用程序

这是我的 ts.config
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"strict": true,
"strictNullChecks": false,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noImplicitAny": false,
"baseUrl": ".",
"types": ["webpack-env", "mocha", "chai"],
"paths": {
"@/*": ["src/*"]
},
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
"exclude": ["node_modules"]
}

package.json
{
"name": "rating-form",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"axios": "^0.18.0",
"bootstrap": "^4.1.3",
"jquery": "^3.3.1",
"moment": "^2.22.2",
"popper.js": "^1.14.4",
"toastr": "^2.1.4",
"vue": "^2.5.17",
"vue-class-component": "^6.0.0",
"vue-property-decorator": "^7.0.0",
"vue-router": "^3.0.1",
"vue-slider-component": "^2.8.0"
},
"devDependencies": {
"@types/chai": "^4.1.0",
"@types/mocha": "^5.2.4",
"@types/node": "^10.12.9",
"@types/qs": "^6.5.1",
"@types/toastr": "^2.1.35",
"@vue/cli-plugin-typescript": "^3.1.1",
"@vue/cli-plugin-unit-mocha": "^3.1.1",
"@vue/cli-service": "^3.1.1",
"@vue/test-utils": "^1.0.0-beta.20",
"chai": "^4.1.2",
"ts-node": "^7.0.1",
"typescript": "^3.1.6",
"vue-template-compiler": "^2.5.17"
}
}

最佳答案

tsconfig.json ,您必须添加 "node""types"大批:

    "baseUrl": ".",
"types": ["webpack-env", "mocha", "chai", "node"],
"paths": {
...或完全删除数组(这就是我要做的):
    "baseUrl": ".",
"paths": {

关于node.js - Node 将 url 和查询字符串类型导入 TypeScript 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53412489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com