使用Angular CLI 6运行ng serve Angular 4,这可能吗?

时间:2018-09-06 22:13:43

标签: angular angular-cli

我有一个使用Angular 4的项目。

我更新了Angular CLI:

Angular CLI: 6.1.5
Node: 10.9.0
OS: win32 x64

那么,如何使用Angular 4为我的项目运行ng serve

Angular 4不存在文件angular.json

谢谢。

Local workspace file ('angular.json') could not be found.
Error: Local workspace file ('angular.json') could not be found.

3 个答案:

答案 0 :(得分:1)

AngularCLI密切关注Angular版本。特别是对于angular.json这样的开关,我怀疑是否有任何有效的方法来处理这种情况。 如果无法升级项目,建议您降级Angular CLI。

请注意,即使https://update.angular.io/也不建议跨多个主要版本迁移项目。

  

警告:我们不建议跨多个主要版本进行迁移。

但是,即使您选择升级一个主要版本,也需要做一些事情来解决该问题。无论如何,这是一个困难的话题。如果您使用的是旧版应用程序而又没有简便的升级方法,建议您降级Angular CLI。

答案 1 :(得分:1)

如果AngularCLI 6的版本低于编译器的版本(5.X.X或更低),则无法使用AngularCLI 6运行任何angular应用程序,但是可以有多个AngularCLI版本。

我建议您在PC上安装最新版本的AngularCLI,并在package.json中指定其他版本。在每次启动时,您都会收到一条警告,提示“您的AngularCLI版本大于package.json中的版本。将使用本地版本,而不是全局版本。”。这只是一条消息,什么都不做。

答案 2 :(得分:0)

谢谢所有答案。

因此,在开发环境中,我可以使用命令npm installng serve运行。 npm install之后,Angular CLI: 6.1.1更改为@angular/cli: 1.1.1

ngupgrade $] npm install
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated hoek@2.16.3: The major version is no longer supported. Please update to 4.x or newer

> node-sass@4.9.3 install C:\dev\wks\wks-lab\ngUpgrade-without-preparation\node_modules\node-sass
> node scripts/install.js

Cached binary found at C:\Users\alisson\AppData\Roaming\npm-cache\node-sass\4.9.3\win32-x64-64_binding.node

> node-sass@4.9.3 postinstall C:\dev\wks\wks-lab\ngUpgrade-without-preparation\node_modules\node-sass
> node scripts/build.js

Binary found at C:\dev\wks\wks-lab\ngUpgrade-without-preparation\node_modules\node-sass\vendor\win32-x64-64\binding.node
Testing binary
Binary is fine
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","ar
ch":"x64"})

added 1094 packages from 1162 contributors and audited 5834 packages in 381.117s
found 15 vulnerabilities (9 low, 6 high)
  run `npm audit fix` to fix them, or `npm audit` for details

ngupgrade $]ng -v
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / ? \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.1.1
node: 10.9.0
os: win32 x64
@angular/animations: 4.4.7
@angular/common: 4.4.7
@angular/compiler: 4.4.7
@angular/core: 4.4.7
@angular/forms: 4.4.7
@angular/http: 4.4.7
@angular/platform-browser: 4.4.7
@angular/platform-browser-dynamic: 4.4.7
@angular/router: 4.4.7
@angular/upgrade: 4.4.7
@angular/cli: 1.1.1
@angular/compiler-cli: 4.4.7
@angular/language-service: 4.4.7

ngupgrade $]ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 **
Hash: 6297789187cf54cae976
Time: 16458ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 195 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 10.7 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 10.5 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.59 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
webpack: Compiled successfully.
^CTerminate batch job (Y/N)? Y

ngupgrade $]