Angular Router 示例 升级以包含 .angular-cli.json 并绕过的最佳方法无法读取 null 的属性“config" [英] Angular Router example Best way to upgrade to include .angular-cli.json and bypass Cannot read property 'config' of null

查看:19
本文介绍了Angular Router 示例 升级以包含 .angular-cli.json 并绕过的最佳方法无法读取 null 的属性“config"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从此页面

下载路由和导航示例

这是特定zip的链接.

我运行以下命令序列:

  1. npm 安装
  2. npm install --save-dev @angular/cli@latest
  3. ng -v
  4. ng serve -o

据我所知无法读取 null 的属性 'config'某种程度上与 CLI 的错误版本有关.但是如果我创建一个新项目,我可以使用我现有的设置成功启动它

  1. 新路由器
  2. cd 路由器
  3. npm 安装
  4. ng serve -o

旧目录结构(来自 zip 下载)包括以下文件:

  • bs-config.json
  • e2e-spec.ts

新目录结构(来自 ng new):

  • .angular-cli.json
  • e2e 是一个包含文件的文件夹
  • karma.conf.js
  • protractor.conf.js
  • tsconfig.json

是否有某种 ng upgrade 命令来转换项目?
有一些关于 Git 关于 ng init 的讨论,但这似乎已成为过去.
我相信大部分文件都与端到端测试有关.

<前>安装npm WARN 已弃用 minimatch@0.3.0:请更新到 minimatch 3.0.2 或更高版本以避免 RegExp DoS 问题npm WARN 已弃用 node-uuid@1.4.8:改用 uuid 模块> phantomjs-prebuilt@2.1.14 安装/opt/AngularProjects/router/node_modules/phantomjs-prebuilt> 节点安装.js在 PATH 上找不到 PhantomJS下载已在/var/folders/xz/sgpc803n1ms6xpc5n571ytc80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip先前下载文件的验证校验和提取 zip 内容删除/opt/AngularProjects/router/node_modules/phantomjs-prebuilt/lib/phantom复制提取的文件夹/var/folders/xz/sgpc803n1ms6xpc5n571ytc80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip-extract-1498561599287/phantomjs-2.1.1-macosx/Project_jssoptrmodule->/Angtomnode-routermodule预建/库/幻影编写 location.js 文件完毕.Phantomjs 二进制文件位于/opt/AngularProjects/router/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs> fsevents@1.1.2 安装/opt/AngularProjects/router/node_modules/fsevents> 节点安装[fsevents] 成功:/opt/AngularProjects/router/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node"已经安装通过 --update-binary 重新安装或 --build-from-source 重新编译npm 通知创建了一个锁文件作为 package-lock.json.你应该提交这个文件.在 20.239 秒内添加了 767 个包ng服务-o无法在 devDependencies 中找到@angular/cli".请采取以下步骤以避免出现问题:npm install --save-dev @angular/cli@latest"您必须在 Angular CLI 项目中才能使用 serve 命令./opt/AngularProjects/路由器>npm install --save-dev @angular/cli@latestnpm WARN 更喜欢全局 node-gyp@3.6.2 应该使用 -g 安装> node-sass@4.5.3 安装/opt/AngularProjects/router/node_modules/node-sass> 节点脚本/install.js缓存二进制文件位于/Users/jgf/.npm/node-sass/4.5.3/darwin-x64-57_binding.node> node-sass@4.5.3 postinstall/opt/AngularProjects/router/node_modules/node-sass> 节点脚本/build.js二进制文件位于/opt/AngularProjects/router/node_modules/node-sass/vendor/darwin-x64-57/binding.node测试二进制文件二进制没问题+ @angular/cli@1.1.3在 17.132 秒内添加了 431 个包==ng -v_ _ ____ _ ___/\ _ __ __ _ _ _||__ _ _ __/___|||_ _|/△ \ |'_ \/_` |||||/_` |'__|||||||/___ \||||(_| | |_| | | (_| | | | |___| |___ | |/_/\_\_||_|\__, |\__,_|_|\__,_|_|\____|_____|___||___/@角度/cli:1.1.3节点:8.1.2操作系统:达尔文 x64@角度/动画:4.2.4@angular/common: 4.2.4@角度/编译器:4.2.4@angular/compiler-cli: 4.2.4@角度/核心:4.2.4@角度/表格:4.2.4@角度/http:4.2.4@angular/平台浏览器:4.2.4@angular/platform-b​​rowser-dynamic: 4.2.4@角度/平台服务器:4.2.4@角度/路由器:4.2.4@angular/tsc-wrapped: 4.2.4@角度/升级:4.2.4@角度/cli:1.1.3ng服务-o无法读取 null 的属性config"类型错误:无法读取 null 的属性config"在 Class.run (/opt/AngularProjects/router/node_modules/@angular/cli/tasks/serve.js:22:63)在 check_port_1.checkPort.then.port (/opt/AngularProjects/router/node_modules/@angular/cli/commands/serve.js:110:26)在在 process._tickCallback (internal/process/next_tick.js:169:7)

关于以下错误:
/opt/AngularProjects/router/node_modules/@angular/cli/tasks/serve.js
我们有:

const config_1 = require("../models/config");...const projectConfig = config_1.CliConfig.fromProject().config;

我怀疑这与丢失的 .angular-cli.json 文件有关./opt/AngularProjects/router/node_modules/@angular/cli/models/config.d.ts

/opt/AngularProjects/router/node_modules/@angular/cli/models/config.js
参考一下.

解决方案

该项目(zip 文件中的项目)未设置为基于 CLI 的项目.但是打开它之后,您可以通过执行以下操作来使其运行:

  • npm 安装
  • npm 运行开始

这将打开您的默认浏览器以http://localhost:3000/ 运行应用程序.

注意:您还需要撤消所做的任何更改(或再次解压缩)

I tried downloading the Routing and Navigation example from this page

Here's the link to the specific zip.

I run the following sequence of commands:

  1. npm install
  2. npm install --save-dev @angular/cli@latest
  3. ng -v
  4. ng serve -o

From what I can make out Cannot read property 'config' of null is somehow related to a bad version of the CLI. But if I create a new project I can start it successfully with my existing setup

  1. ng new router
  2. cd router
  3. npm install
  4. ng serve -o

Old directory structure (from zip download) includes these files:

  • bs-config.json
  • e2e-spec.ts

New directory structure (from ng new):

  • .angular-cli.json
  • e2e is a folder with files inside
  • karma.conf.js
  • protractor.conf.js
  • tsconfig.json

Is there some sort of ng upgrade command to convert a project?
There was some talk on Git about ng init, but that seems to now be a thing of the past.
I believe most of the files are related to end to end testing.

    npm install
    npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
    npm WARN deprecated node-uuid@1.4.8: Use uuid module instead

    > phantomjs-prebuilt@2.1.14 install /opt/AngularProjects/router/node_modules/phantomjs-prebuilt
    > node install.js

    PhantomJS not found on PATH
    Download already available at /var/folders/xz/sgpc803n1ms6xpc5n571ytc80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip
    Verified checksum of previously downloaded file
    Extracting zip contents
    Removing /opt/AngularProjects/router/node_modules/phantomjs-prebuilt/lib/phantom
    Copying extracted folder /var/folders/xz/sgpc803n1ms6xpc5n571ytc80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip-extract-1498561599287/phantomjs-2.1.1-macosx -> /opt/AngularProjects/router/node_modules/phantomjs-prebuilt/lib/phantom
    Writing location.js file
    Done. Phantomjs binary available at /opt/AngularProjects/router/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs

    > fsevents@1.1.2 install /opt/AngularProjects/router/node_modules/fsevents
    > node install

    [fsevents] Success: "/opt/AngularProjects/router/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
    Pass --update-binary to reinstall or --build-from-source to recompile
    npm notice created a lockfile as package-lock.json. You should commit this file.
    added 767 packages in 20.239s


    ng serve -o
    Unable to find "@angular/cli" in devDependencies.

    Please take the following steps to avoid issues:
    "npm install --save-dev @angular/cli@latest" 

    You have to be inside an Angular CLI project in order to use the serve command.
    /opt/AngularProjects/router>


    npm install --save-dev @angular/cli@latest
    npm WARN prefer global node-gyp@3.6.2 should be installed with -g

    > node-sass@4.5.3 install /opt/AngularProjects/router/node_modules/node-sass
    > node scripts/install.js

    Cached binary found at /Users/jgf/.npm/node-sass/4.5.3/darwin-x64-57_binding.node

    > node-sass@4.5.3 postinstall /opt/AngularProjects/router/node_modules/node-sass
    > node scripts/build.js

    Binary found at /opt/AngularProjects/router/node_modules/node-sass/vendor/darwin-x64-57/binding.node
    Testing binary
    Binary is fine
    + @angular/cli@1.1.3
    added 431 packages in 17.132s

    ==
    ng -v
        _                      _                 ____ _     ___
       / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
      / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
     / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
    /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                   |___/
    @angular/cli: 1.1.3
    node: 8.1.2
    os: darwin x64
    @angular/animations: 4.2.4
    @angular/common: 4.2.4
    @angular/compiler: 4.2.4
    @angular/compiler-cli: 4.2.4
    @angular/core: 4.2.4
    @angular/forms: 4.2.4
    @angular/http: 4.2.4
    @angular/platform-browser: 4.2.4
    @angular/platform-browser-dynamic: 4.2.4
    @angular/platform-server: 4.2.4
    @angular/router: 4.2.4
    @angular/tsc-wrapped: 4.2.4
    @angular/upgrade: 4.2.4
    @angular/cli: 1.1.3


    ng serve -o
    Cannot read property 'config' of null
    TypeError: Cannot read property 'config' of null
        at Class.run (/opt/AngularProjects/router/node_modules/@angular/cli/tasks/serve.js:22:63)
        at check_port_1.checkPort.then.port (/opt/AngularProjects/router/node_modules/@angular/cli/commands/serve.js:110:26)
        at 
        at process._tickCallback (internal/process/next_tick.js:169:7)

In relation to the error in:
/opt/AngularProjects/router/node_modules/@angular/cli/tasks/serve.js
we have:

const config_1 = require("../models/config");
...
const projectConfig = config_1.CliConfig.fromProject().config;

I suspect this pertains to a missing .angular-cli.json file. /opt/AngularProjects/router/node_modules/@angular/cli/models/config.d.ts
and
/opt/AngularProjects/router/node_modules/@angular/cli/models/config.js
refer to it.

解决方案

That project (the one in the zip file) is not setup as a CLI-based project. But after opening it up, you can get it running by doing the following:

  • npm install
  • npm run start

This will open your default browser to http://localhost:3000/ where the app will be running.

NOTE: you'll also want to undo any changes you've made (or unzip again)

这篇关于Angular Router 示例 升级以包含 .angular-cli.json 并绕过的最佳方法无法读取 null 的属性“config"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆