nestjs / nest-cli

CLI tool for Nest applications 🍹
https://nestjs.com
Other
1.97k stars 394 forks source link

'nest generate sub-app' chokes on Invalid JSON character #418

Closed theRocket closed 5 years ago

theRocket commented 5 years ago

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Try to generate a sub-app (in this case, with --dry-run option but it also happens without) and receive the following error:

➜  proteuserver2 git:(develop) ✗ nest g sub-app --dry-run
? What name would you like to use for the app? morningstar
Error: Invalid JSON character: "\"" at 12:5.
    at _token (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:81:19)
    at _readProperty (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:490:5)
    at _readObject (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:524:30)
    at _readValue (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:674:22)
    at _readProperty (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:491:19)
    at _readObject (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:515:26)
    at _readValue (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:674:22)
    at parseJsonAst (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:721:17)
    at Object.parseJson (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/node_modules/@angular-devkit/core/src/json/parser.js:750:24)
    at updateJsonFile (/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/@nestjs/schematics/lib/sub-app/sub-app.factory.js:74:29)

Failed to execute command: "/Users/rjr/.nvm/versions/node/v10.16.0/lib/node_modules/@nestjs/cli/node_modules/.bin/schematics" @nestjs/schematics:sub-app --dry-run --spec --collection="@nestjs/schematics" --language="ts" --sourceRoot="src"

Expected behavior

Files to be generated and code to be changed is described in some readable form in command output.

Minimal reproduction of the problem with instructions

> npm install -g @nestjs/cli                  
+ @nestjs/cli@6.10.5
> nest g sub-app --dry-run

What is the motivation / use case for changing the behavior?

I want to use the command to generate a sub-app.

Environment

> nest info

 _   _             _      ___  _____  _____  _     _____
| \ | |           | |    |_  |/  ___|/  __ \| |   |_   _|
|  \| |  ___  ___ | |_     | |\ `--. | /  \/| |     | |
| . ` | / _ \/ __|| __|    | | `--. \| |    | |     | |
| |\  ||  __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/  \____/\_____/\___/

[System Information]
OS Version     : macOS Mojave
NodeJS Version : v10.16.0
YARN Version    : 1.19.0
[Nest Information]
platform-express version : 6.8.3
microservices version    : 6.8.3
passport version         : 6.1.0
graphql version          : 6.5.3
swagger version          : 3.1.0
common version           : 6.8.3
core version             : 6.8.3
jwt version              : 6.1.1
johnbiundo commented 5 years ago

@theRocket A sub-app can only be added to an existing "workspace". So you'll need to first nest new an app, then cd to that app folder, then run nest g app in that folder.

If that's what you already did (which isn't what you described above), then the next possibility is that the package.json is malformed. Take a look at line 12 of the package.json to see.

theRocket commented 5 years ago

I am working within an existing app. It is a fork of this project: https://github.com/fivethree-team/nestjs-prisma-starter/blob/master/package.json When I clone that repo again and run the command within the directory, 'nest g app' worked. So you are right, there must be something wrong with my package.json file.