← 输入框|github.com|刷新
Skip to content

ng new mistakenly thinks it's in a project #4762

Closed

Description

@Meligy

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

Windows 8.1

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

@angular/cli: 1.0.0-beta.31
node: 6.9.4
os: win32 x64
@angular/cli: 1.0.0-beta.31

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

mkdir sample
cd sample
yarn add @nagular/cli
node_modules/.bin/ng new sample -dir=.

The log given by the failure.

Normally this include a stack trace and some more information.

You cannot use the new command inside an Angular CLI project.

Mention any other details that might be useful.

  1. This is because the command checks for whether it's in project by looking for the package @angular/cli under node_modules
  2. I think it should be looking for config file .angular-cli.json instead
  3. This is important as ng init / ng update is now gone. It allows me to use the CLI without global installation, earlier I used ng init for this
  4. I'm NOT asking for this to work in existing CLI project. This is NOT a request to make new act as init. The scenario I'm asking to support is when the package exists, but no other files like package.json or .angular-cli.json are present, that is, no Angular CLI project in the folder

Thanks! We'll be in touch soon.

Activity

  1. Meligy commented on Feb 16, 2017

    @Meligy
    ContributorAuthor

    Happy to look at implementation if we agree we want to make that change, which is detecting project presence based on config file .angular-cli.json not presence of node_modules/@angular/cli/.

  2. hansl commented on Feb 16, 2017

    @hansl
    Contributor

    You have an node_modules folder somewhere in your path (a parent directory or something). Look for a package.json file somewhere, or a node_modules directory. Delete those and you'll be fine.

    Most of the time those are in your HOME folder.

  3. Meligy commented on Feb 16, 2017

    @Meligy
    ContributorAuthor

    @hansl did you check the repro steps?

  4. Meligy commented on Feb 17, 2017

    @Meligy
    ContributorAuthor

    @hansl I double checked - I don't.

    But anyway, are you suggesting that the mentioned steps above are not supposed to bring the mentioned message?

  5. hansl commented on Feb 17, 2017

    @hansl
    Contributor

    OH okay. No I didn't. I just see those and copy-paste the message lol

  6. hansl commented on Feb 17, 2017

    @hansl
    Contributor

    The Angular CLI does use node_modules to detect if it's in a project. This is by design and unlikely to change (it's Ember-CLI specific logic).

  7. Meligy commented on Feb 17, 2017

    @Meligy
    ContributorAuthor

    I can see the check is made here https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/ember-cli/lib/models/project.js#L117

    It's part of the Angular CLI project, and we modified the file a few times already. If we agree on the principle that the check should be based on presence of Angular CLI config file, that'd be awesome.

    We have diverged from the ember CLI anyway (Ember still has an init command for example, although again, this is NOT aimed at making new like init). This will enable #4768 for example.

  8. reopened this on Feb 22, 2017
  9. added a commit that references this issue on Feb 22, 2017
    e4fc294
  10. Meligy commented on Feb 22, 2017

    @Meligy
    ContributorAuthor

    Thanks a lot @hansl and @filipesilva 💯

  11. machucarro commented on Mar 10, 2017

    @machucarro

    I'm using the v.1.0.0-rc1 and still having the same issue. In order to initialize a project with local cli by
    running:
    npm init
    npm install @angular/cli --save-dev
    modifying package.json adding script: "ng": "node_modules\.bin\ng"
    and running:
    npm run ng -- new my-project -dir=.

    I still get: "You cannot use the new command inside an Angular CLI project."

    There are tons of practical reasons why this approach is for us better than having cli globally installed

  12. filipesilva commented on Mar 13, 2017

    @filipesilva
    Contributor

    @machucarro I just tried this myself and it works. See below for a log of what I did.

    Maybe you have a CLI config file somewhere up in the directory tree?

    kamik@T460p MINGW64 /D/sandbox
    $ mkdir local-proj
    
    kamik@T460p MINGW64 /D/sandbox
    $ cd local-proj/
    
    kamik@T460p MINGW64 /D/sandbox/local-proj
    $ npm install @angular/cli
    # ...
    
    kamik@T460p MINGW64 /D/sandbox/local-proj
    $ $(npm bin)/ng new local-proj --dir=./ --skip-install
    installing ng
      create .editorconfig
      create README.md
      create src\app\app.component.css
      create src\app\app.component.html
      create src\app\app.component.spec.ts
      create src\app\app.component.ts
      create src\app\app.module.ts
      create src\assets\.gitkeep
      create src\environments\environment.prod.ts
      create src\environments\environment.ts
      create src\favicon.ico
      create src\index.html
      create src\main.ts
      create src\polyfills.ts
      create src\styles.css
      create src\test.ts
      create src\tsconfig.app.json
      create src\tsconfig.spec.json
      create src\typings.d.ts
      create .angular-cli.json
      create e2e\app.e2e-spec.ts
      create e2e\app.po.ts
      create e2e\tsconfig.e2e.json
      create .gitignore
      create karma.conf.js
      create package.json
      create protractor.conf.js
      create tsconfig.json
      create tslint.json
    Successfully initialized git.
    You can `ng set --global packageManager=yarn`.
    Project 'local-proj' successfully created.
    
  13. added a commit that references this issue on Apr 12, 2017
    3f2eda1
  14. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    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.

  15. locked and limited conversation to collaborators on Sep 6, 2019
  16. added a commit that references this issue on May 29, 2026
    8941139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions