从Angular 7迁移到Angular 8

时间:2019-06-11 06:19:26

标签: node.js angular typescript

当我将代码从Angular 7迁移到Angular 8并完成迁移时,但是当我使用npm start运行应用程序时,它会出现以下错误

ERROR in The Angular Compiler requires TypeScript >=3.4.0 and <3.5.0 but 3.5.1 was found instead.
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
i 「wdm」: Failed to compile.

因此,我正在尝试使用npm i typescript@3.4.0 --save-dev --save-exact将打字稿版本从3.5.1降级到3.4.0

它显示以下错误

npm ERR! code ETARGET
npm ERR! notarget No matching version found for typescript@3.4.0
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Hp\AppData\Roaming\npm-cache\_logs\2019-06-11T06_02_56_125Z-debug.log

文件具有这些内容

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'i',
1 verbose cli   'typescript@3.4.0',
1 verbose cli   '--save-dev',
1 verbose cli   '--save-exact'
1 verbose cli ]
2 info using npm@6.9.0
3 info using node@v12.4.0
4 verbose npm-session 34e826751150af7e
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 304 https://registry.npmjs.org/typescript 624ms (from cache)
8 silly registry:manifest no matching version for typescript@3.4.0 in the cache. Forcing revalidation.
9 http fetch GET 200 https://registry.npmjs.org/typescript 717ms
10 silly fetchPackageMetaData error for typescript@3.4.0 No matching version found for typescript@3.4.0
11 timing stage:rollbackFailedOptional Completed in 3ms
12 timing stage:runTopLevelLifecycles Completed in 4809ms
13 verbose type version
14 verbose stack typescript: No matching version found for typescript@3.4.0
14 verbose stack     at pickManifest (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-pick-manifest\index.js:101:11)
14 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\manifest.js:43:18
14 verbose stack     at tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
14 verbose stack     at Promise._settlePromiseFromHandler (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:512:31)
14 verbose stack     at Promise._settlePromise (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:569:18)
14 verbose stack     at Promise._settlePromise0 (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:614:10)
14 verbose stack     at Promise._settlePromises (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:694:18)
14 verbose stack     at _drainQueueStep (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:138:12)
14 verbose stack     at _drainQueue (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:131:9)
14 verbose stack     at Async._drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:147:5)
14 verbose stack     at Immediate.Async.drainQueues [as _onImmediate] (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
14 verbose stack     at processImmediate (internal/timers.js:439:21)
15 verbose cwd E:\ng72ng8\Fxt\Web\src\main\ui\material
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i" "typescript@3.4.0" "--save-dev" "--save-exact"
18 verbose node v12.4.0
19 verbose npm  v6.9.0
20 error code ETARGET
21 error notarget No matching version found for typescript@3.4.0
22 error notarget In most cases you or one of your dependencies are requesting
22 error notarget a package version that doesn't exist.
23 verbose exit [ 1, true ]

有人可以帮我解决这个问题吗?

谢谢。

3 个答案:

答案 0 :(得分:1)

没有Typescript的版本3.4.0,可以将其设置为其他版本(可以在https://www.npmjs.com/package/typescript的“ Versions”标签下查看),也可以使版本类似{{1 }}

答案 1 :(得分:0)

  

Angular 8支持TypeScript 3.4或更高版本。所以,如果我们想要   要在我们的应用程序中使用Angular 8,那么我们需要先升级   TypeScript达到3.4或更高版本。

Typescript 3.4.0版本处于开发模式,您可以在typescript version上看到它,因此您需要在3.4.0中将Typescript版本从3.4.3更改为package.json文件。

答案 2 :(得分:0)

我在有角度的8应用程序中使用"typescript": "~3.4.5"。对我来说,它按预期工作。 尝试升级所有可以通过使用以下方式升级的依赖项:

ng update @angular/cli @angular/core

OR

ng update --all

有时此命令会引发库不匹配的问题,在这种情况下,您可以使用类似的

ng update --force

此命令将强制更新所有依赖关系,其余对等依赖关系可以手动更新。