Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Meligy opened this issue Feb 16, 2017 · 11 comments
Closed

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

Meligy opened this issue Feb 16, 2017 · 11 comments

Comments

@Meligy
Copy link
Contributor

Meligy commented Feb 16, 2017

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.

@Meligy
Copy link
Contributor Author

Meligy commented Feb 16, 2017

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/.

@hansl
Copy link
Contributor

hansl commented Feb 16, 2017

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.

@hansl hansl closed this as completed Feb 16, 2017
@Meligy
Copy link
Contributor Author

Meligy commented Feb 16, 2017

@hansl did you check the repro steps?

@Meligy
Copy link
Contributor Author

Meligy commented Feb 17, 2017

@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?

@hansl
Copy link
Contributor

hansl commented Feb 17, 2017

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

@hansl
Copy link
Contributor

hansl commented Feb 17, 2017

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).

@Meligy
Copy link
Contributor Author

Meligy commented Feb 17, 2017

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.

@Meligy
Copy link
Contributor Author

Meligy commented Feb 22, 2017

Thanks a lot @hansl and @filipesilva 💯

@machucarro
Copy link

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

@filipesilva
Copy link
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.

asnowwolf pushed a commit to asnowwolf/angular-cli that referenced this issue Apr 12, 2017
Unless the directory is already under an Angular CLI project.

Fixes angular#4762
Close angular#4901
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants