我正在尝试从 1.X ServiceStack/Client 库升级到 2.X 版本
升级后运行“ng build”时出现以下错误(最新的 1.X 工作正常):
node:fs - Error: Module build failed: UnhandledSchemeError: Reading from "node:fs" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
node:path - Error: Module build failed: UnhandledSchemeError: Reading from "node:path" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
可能是什么问题?
这是已安装的 npm 包列表:
+-- @angular-devkit/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @angular/[email protected]
+-- @ng-bootstrap/[email protected]
+-- @ngx-translate/[email protected]
+-- @ngx-translate/[email protected]
+-- @popperjs/[email protected]
+-- @servicestack/[email protected]
+-- @types/[email protected]
+-- @types/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
npm -v: 9.6.0
节点-v:v18.14.2
那是我的 package.json:
{
"name": "portal",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "echo Starting 'ng serve'... && ng serve",
"start:iis": "echo Starting 'ng build --watch'... && ng build --watch",
"build": "ng build",
"build:ssr": "ng run Portal:server:dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ngcc"
},
"private": true,
"dependencies": {
"@angular/animations": "14.2.12",
"@angular/common": "14.2.12",
"@angular/compiler": "14.2.12",
"@angular/core": "14.2.12",
"@angular/forms": "14.2.12",
"@angular/platform-browser": "14.2.12",
"@angular/platform-browser-dynamic": "14.2.12",
"@angular/router": "14.2.12",
"@ng-bootstrap/ng-bootstrap": "13.1.1",
"@ngx-translate/core": "^14.0.0",
"@ngx-translate/http-loader": "^7.0.0",
"@popperjs/core": "^2.11.6",
"@servicestack/client": "^2.0.7",
"angular-code-input": "^1.6.0",
"bootstrap": "^5.2.3",
"core-js": "^3.29.0",
"google-libphonenumber": "^3.2.32",
"jquery": "^3.6.3",
"node-fs": "^0.1.7",
"rxjs": "^7.8.0",
"ts-node": "^10.9.1",
"tslib": "^2.5.0",
"zone.js": "^0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "14.2.10",
"@angular/cli": "14.2.10",
"@angular/compiler-cli": "14.2.12",
"@angular/language-service": "14.2.12",
"@types/google-libphonenumber": "^7.4.23",
"@types/node": "^18.14.6",
"node-libs-browser": "^2.2.1",
"typescript": "4.8.4"
},
"optionalDependencies": {
"tslint": "~6.1.3"
}
}
那是我的 tsconfig:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"experimentalDecorators": true,
"types": [ "node" ],
"target": "es2020"
},
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
那是我的 angular.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"cli": {
"analytics": false
},
"version": 1,
"newProjectRoot": "projects",
"projects": {
"Portal": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"progress": false,
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/assets"
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css"
],
"scripts": [],
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true,
"allowedCommonJsDependencies": [ "google-libphonenumber", "@servicestack/client" ]
},
"configurations": {
"production": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
},
"defaultConfiguration": ""
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "Portal:build"
},
"configurations": {
"production": {
"browserTarget": "Portal:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "Portal:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [ "src/styles.css" ],
"scripts": [],
"assets": [ "src/assets" ]
}
},
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist-server",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.server.json",
"sourceMap": true,
"optimization": false
},
"configurations": {
"dev": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true
},
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true
}
},
"defaultConfiguration": ""
}
}
},
"Portal-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "Portal:serve"
}
}
}
}
}
}
v2.x 变化
@servicestack/client 现在没有依赖了
由于在 Node.js v18+ LTS 中可用,因此所有 polyfill 都已被删除,以使 @servicestack/client 在其最新的主要 v2.x 版本中没有依赖性。fetch
在使用其原生的浏览器中使用 JsonServiceClient 或从现在具有原生获取支持的 Node.js v18+ 中使用时,这应该没有影响。fetch()
源链接
所以
fetch
是默认支持的,如果你使用替代方法来获取像 node-fetch
就不再需要了。