angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng build a ng new project error

Open huyinghuan opened this issue 9 years ago • 13 comments

ng --version

@angular/cli: 1.4.5
node: 6.9.5
os: darwin x64
@angular/animations: 4.4.4
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4
@angular/forms: 4.4.4
@angular/http: 4.4.4
@angular/platform-browser: 4.4.4
@angular/platform-browser-dynamic: 4.4.4
@angular/router: 4.4.4
@angular/cli: 1.4.5
@angular/compiler-cli: 4.4.4
@angular/language-service: 4.4.4
typescript: 2.3.4

there are errors:

~/w/test $ ng new ngb
  create ngb/README.md (1019 bytes)
  create ngb/.angular-cli.json (1238 bytes)
  create ngb/.editorconfig (245 bytes)
  create ngb/.gitignore (516 bytes)
  create ngb/src/assets/.gitkeep (0 bytes)
  create ngb/src/environments/environment.prod.ts (51 bytes)
  create ngb/src/environments/environment.ts (387 bytes)
  create ngb/src/favicon.ico (5430 bytes)
  create ngb/src/index.html (290 bytes)
  create ngb/src/main.ts (370 bytes)
  create ngb/src/polyfills.ts (2498 bytes)
  create ngb/src/styles.css (80 bytes)
  create ngb/src/test.ts (1085 bytes)
  create ngb/src/tsconfig.app.json (211 bytes)
  create ngb/src/tsconfig.spec.json (304 bytes)
  create ngb/src/typings.d.ts (104 bytes)
  create ngb/e2e/app.e2e-spec.ts (285 bytes)
  create ngb/e2e/app.po.ts (208 bytes)
  create ngb/e2e/tsconfig.e2e.json (235 bytes)
  create ngb/karma.conf.js (923 bytes)
  create ngb/package.json (1308 bytes)
  create ngb/protractor.conf.js (722 bytes)
  create ngb/tsconfig.json (363 bytes)
  create ngb/tslint.json (2968 bytes)
  create ngb/src/app/app.module.ts (314 bytes)
  create ngb/src/app/app.component.css (0 bytes)
  create ngb/src/app/app.component.html (1120 bytes)
  create ngb/src/app/app.component.spec.ts (986 bytes)
  create ngb/src/app/app.component.ts (207 bytes)
Installing packages for tooling via cnpm.
Installed packages for tooling via cnpm.
Successfully initialized git.
Project 'ngb' successfully created.
~/w/test $ cd ngb
~/w/t/ngb (master|✔) $ ng build --prod
 95% emittingUnhandled rejection Error: ENOENT: no such file or directory, open '/Users/hyh/workspace/test/ngb/node_modules/_@[email protected]@@angular/package.json'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at LicenseExtractor.readPackageJson (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@license-webpack-plugin/dist/LicenseExtractor.js:124:23)
    at LicenseExtractor.parsePackage (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@license-webpack-plugin/dist/LicenseExtractor.js:21:32)
    at ModuleProcessor.processPackage (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@license-webpack-plugin/dist/ModuleProcessor.js:24:46)
    at ModuleProcessor.processFile (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@license-webpack-plugin/dist/ModuleProcessor.js:21:21)
    at moduleCallback (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@license-webpack-plugin/dist/LicenseWebpackPlugin.js:80:61)
    at SortableSet.forEach (native)
    at Chunk.forEachModule (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@webpack/lib/Chunk.js:159:17)
    at /Users/hyh/workspace/test/ngb/node_modules/[email protected]@license-webpack-plugin/dist/LicenseWebpackPlugin.js:89:27
    at Array.forEach (native)
    at Compiler.<anonymous> (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@license-webpack-plugin/dist/LicenseWebpackPlugin.js:65:32)
    at next (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@tapable/lib/Tapable.js:204:14)
    at /Users/hyh/workspace/test/ngb/node_modules/[email protected]@html-webpack-plugin/index.js:204:9
    at PassThroughHandlerContext.finallyHandler (/Users/hyh/workspace/test/ngb/node_modules/[email protected]@bluebird/js/release/finally.js:56:23)

huyinghuan avatar Oct 10 '17 01:10 huyinghuan

npm uninstall -g @angular/cli
npm cache clean
# if npm version is > 5 then use
npm cache verify # to avoid errors (or to avoid using --force)
npm install -g @angular/cli@latest

Read here for details

yosefbennywidyo avatar Oct 10 '17 02:10 yosefbennywidyo

@fybwid yes, I have done. but the error still exists

huyinghuan avatar Oct 10 '17 02:10 huyinghuan

@huyinghuan It definitely works for me after a reinstall.

Perhaps post a copy of npm ls to show what exact package versions you're using?

shadowmint avatar Oct 10 '17 02:10 shadowmint

@huyinghuan same here.

Rmsilva1 avatar Oct 10 '17 02:10 Rmsilva1

@shadowmint npm ls too many code output.

I modify the file node_modules/[email protected]@license-webpack-plugin/dist/LicenseExtractor.js line:122

    LicenseExtractor.prototype.readPackageJson = function (packageName) {
        var pathName = path.join(this.modulePrefix, packageName, 'package.json');
       // add some code: start
        if(!fs.existsSync(pathName)){
            if(packageName.indexOf("_@angular_")!=-1){
                pathName = path.join(this.modulePrefix, packageName, packageName.split("@")[1].replace("angular_", ""), 'package.json');
            }
        }
      //========= end
        var file = fs.readFileSync(pathName, 'utf8');
        return JSON.parse(file);
    };

it can work fine.

huyinghuan avatar Oct 10 '17 02:10 huyinghuan

the errors only exists when use args --prod. if just use --aot --environment=prod it can work fine

huyinghuan avatar Oct 10 '17 02:10 huyinghuan

image

maybe bug in here

huyinghuan avatar Oct 10 '17 02:10 huyinghuan

I found the bug, fix:

/Users/hyh/workspace/test/ng4/node_modules/[email protected]@license-webpack-plugin/dist/ModuleProcessor.js

line: 34

from

tokens[0].charAt(0) === '@' 
                ? tokens.slice(0, 2).join('/')
                : tokens[0];

to

(tokens[0].charAt(0) === '@' || tokens[0].indexOf('_@') === 0)
                ? tokens.slice(0, 2).join('/')
                : tokens[0];

huyinghuan avatar Oct 10 '17 02:10 huyinghuan

@huyinghuan did not worked for me, im trying to generate a compoment, but im having the same trouble...

Rmsilva1 avatar Oct 10 '17 02:10 Rmsilva1

@Rmsilva1 I cant generate a compoment too 😂 errors is:

Error: ELOOP: too many symbolic links encountered, stat '/Users/hyh/workspace/test/ng4/node_modules/@angular/cli/node_modules/webpack/xxxx/....

Maybe we install wrong angular-cli version .....

huyinghuan avatar Oct 10 '17 03:10 huyinghuan

@huyinghuan I have uninstalled Node, and installed the 8 version, removed the angular cli from the folder of my project and then cleaned the cache of the npm with --force , installed the latest version of angular cli and then it worked for me 👍

Rmsilva1 avatar Oct 10 '17 03:10 Rmsilva1

@huyinghuan it fixed my problem to generate new Angular app. Recommended

npm cache clear #or
npm cache rm

Not recommended

npm cache clean --force

Note from npm help cache:

All  data  that passes through the cache is fully verified for integrity on both insertion and extraction.
Cache corruption will either trigger an error, or signal to pacote that the data must be refetched,
which it will do automatically. For  this  reason, it  should  never  be  necessary to clear the cache
for any reason other than reclaiming disk space, thus why clean now requires `--force` to run.

and then install the latest Angular version:

npm install -g @angular/cli@latest

yosefbennywidyo avatar Oct 10 '17 04:10 yosefbennywidyo

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.