kzuno (6) [Avatar] Offline
#1
Hi,

I'm struggling to set up to run the codes in 4.3.1 of your book.
Your book simply says as follows.
To get started, use the CLI to generate a new project. Navigate to the directory
you’d like to create the project in, and run the following command.
ng new components

And in 1.1.1
You can install the CLI using NPM. It does require that you have Node 4 or newer to run properly.
npm install -g angular-cli

So I tried as follows and got a error.
$ sudo apt-get install nodejs
$ sudo apt-get install nodejs-legacy
$ node -v
v4.2.6
$ sudo apt-get install npm
...
$ npm -v
3.5.2
$ npm install -g angular-cli
...
npm WARN optional Skipping failed optional dependency /angular-cli/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.1.1
npm WARN @angular/core@2.4.8 requires a peer of rxjs@^5.0.1 but none was installed.
$ ng help
/usr/local/lib/node_modules/angular-cli/node_modules/@ngtools/json-schema/src/schema-class-factory.js:34
            result.push(...indices);
                        ^^^

SyntaxError: Unexpected token ...
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/angular-cli/node_modules/@ngtools/json-schema/src/index.js:3:30)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

Could you clarify how to setup ?
If a specific version is required, please show me how to install the exact version of that.
I think this will be very helpful for many of your book readers.
jeremy.wilken (194) [Avatar] Offline
#2
The problem is that you installed a more recent version that the book has been using, which chapter 1 should point to this. It looks like they didn't update this line of the MEAP.

npm install -g angular-cli@v1.0.0-beta.19-3


However, if you installed the latest version, it does require Node 6.9 or newer. Try to update your node version to the current LTS version to continue.
kzuno (6) [Avatar] Offline
#3
Thank you for your response!
I tried to install the specific version of CLI with blandnew EC2 instance, but got an same error.
Shoud I try the recent version? but I'm afraid a compatibility issue with your book's code.

$ sudo apt-get update
...
$ sudo apt-get upgrade
...
$ sudo apt-get install nodejs-legacy
...
$ node -v
v4.2.6
$ sudo apt-get install npm
$ npm -v
3.5.2
$ sudo npm install -g angular-cli@v1.0.0-beta.19-3
...
$ ng help

Unexpected token {
SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/angular-cli/models/webpack-build-typescript.js:5:17)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/angular-cli/models/webpack-config.js:2:34)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/angular-cli/tasks/build-webpack.js:6:24)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/angular-cli/commands/build.js:3:23)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Class.module.exports.includedCommands (/usr/local/lib/node_modules/angular-cli/addon/index.js:21:16)
    at /usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/models/project.js:392:61
    at Array.forEach (native)
    at Project.addonCommands (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/models/project.js:391:15)
    at Project.eachAddonCommand (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/models/project.js:426:30)
    at module.exports (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/cli/lookup-command.js:33:13)
    at CLI.<anonymous> (/usr/local/lib/node_modules/angular-cli/node_modules/angular-cli/lib/cli/cli.js:34:26)
    at tryCatch (/usr/local/lib/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:538:12)
    at invokeCallback (/usr/local/lib/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:553:13)
    at publish (/usr/local/lib/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:521:7)
    at flush (/usr/local/lib/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:2373:5)
    at nextTickCallbackWith0Args (node.js:419:9)
    at process._tickCallback (node.js:348:13)
$
kzuno (6) [Avatar] Offline
#4
I've installed the latest version of CLI (1.0.0-rc.0), and it works well.
I will see whether I can tweek the book's code without compatibility issue.
jeremy.wilken (194) [Avatar] Offline
#5
A newer version of NodeJS should be fine, I use 6.9.x myself. The CLI sometimes requires you to uninstall and reinstall between releases, but starting over with RC1 might work just fine. I just can't any guarantee that they haven't changed something along the way (though I have used many of the versions just fine as well).

Feel free to share questions or issues if you face them with RC1.