generator-jhipster: upgrade fail under windows

Overview of the issue

I tried to upgrade my code to 4.6.2 but encountered error:

$ jhipster upgrade Executing jhipster:upgrade Options: Welcome to the JHipster Upgrade Sub-Generator This will upgrade your current application codebase to the latest JHipster version Looking for latest generator-jhipster version… New generator-jhipster version found: 4.6.2 Git repository detected Checked out branch “jhipster_upgrade” Updating generator-jhipster to 4.6.2 . This might take some time… Updated generator-jhipster to version 4.6.2 Cleaned up directory Regenerating application with JHipster 4.6.2… events.js:160 throw er; // Unhandled ‘error’ event ^

Error: ERROR! Something went wrong while generating project! ‘$’ is not recognized as an internal or external command, operable program or batch file.

at Environment.error (C:\Users\Powerful User\AppData\Local\Yarn\config\global\node_modules\yeoman-environment\lib\environment.js:140:40)
at constructor.error (C:\Users\Powerful User\AppData\Local\Yarn\config\global\node_modules\generator-jhipster\generators\generator-base.js:1610:18)
at shelljs.exec (C:\Users\Powerful User\AppData\Local\Yarn\config\global\node_modules\generator-jhipster\generators\upgrade\index.js:86:23)
at C:\Users\Powerful User\AppData\Local\Yarn\config\global\node_modules\shelljs\src\exec.js:204:9
at ChildProcess.exithandler (child_process.js:211:5)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:886:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
Motivation for or Use Case

To help who encounter same issue under windows when upgrading a jhipster generated project

Reproduce the error

Step 1: yarn global upgrade generator-jhipster

Step 2: jhipster upgrade

This error occurs in power shell AND git bash.

Related issues

None

Suggest a Fix
JHipster Version(s)

Upgraded jhipster generator to 4.6.2 then try to upgrade my code base from 4.5.6 to 4.6.2

JHipster configuration

$ jhipster info Executing jhipster:info Options: Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
C:\code\sibodell-hse\hse-backend
`-- generator-jhipster@4.6.2

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.bigcompany.hse",
      "nativeLanguage": "zh-cn"
    },
    "jhipsterVersion": "4.5.6",
    "baseName": "hse",
    "packageName": "com.bigcompany.hse",
    "packageFolder": "com/bigcompany/hse",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "ehcache",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "jwtSecretKey": "replaced-by-jhipster-info",
    "clientFramework": "angular1",
    "useSass": false,
    "clientPackageManager": "yarn",
    "applicationType": "monolith",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "zh-cn",
    "languages": [
      "zh-cn",
      "en"
    ]
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory

ls: no such file or directory: .jhipster/*.json

JDL entity definitions





Environment and Tools

java version “1.8.0_141” Java™ SE Runtime Environment (build 1.8.0_141-b15) Java HotSpot™ 64-Bit Server VM (build 25.141-b15, mixed mode)

git version 2.12.2.windows.2

node: v6.10.2

npm: 5.0.4

bower: 1.8.0

gulp: [12:11:04] CLI version 1.3.0 [12:11:04] Local version 3.9.1

yeoman: 2.0.0

yarn: 0.27.5

Docker version 1.12.5, build 7392c3b

docker-compose version 1.9.0, build 2585387

Execution complete

Entity configuration(s) entityName.json files generated in the .jhipster directory

NONE (We generated some entities then moved the .json files to other directory, this bug should have nothing to do with entities)

Browsers and Operating System

Windows 10 Pro

  • [* ] Checking this box is mandatory (yes, I’ve read everything)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (27 by maintainers)

Commits related to this issue

Most upvoted comments

yes good idea, I also think we should give an advice to user when an error is thrown during upgrade, something like “please run the same command with --verbose flag”

The upgrade sugbenerator already has a --verbose flag (docs) which outputs all of the shelljs commands, maybe we should merge that with the --debug flag

Thanks, I will use it on the upgrade sub generator.

I changed line 82 from:

generatorCommand = this.clientPackageManager === ‘yarn’ ? ‘$(yarn bin)/jhipster’ : ‘$(npm bin)/jhipster’;

to these two lines:

let generatorDir = this.clientPackageManager === ‘yarn’ ? shelljs.exec(‘yarn bin’) : shelljs.exec(‘npm bin’); generatorCommand = generatorDir.replace(‘\n’, ‘’) + ‘/jhipster’;

Now it works. Out put around these lines are:

… Regenerating application with JHipster 4.6.2… C:\Code\sibodell-hse\hse-backend\node_modules.bin Successfully regenerated application with JHipster 4.6.2 …

Notice there’s output when shelljs.exec(‘yarn bin’) run, should I mute it by adding a parameter { silent: this.silent }? Not familiar with shelljs.

The code might be not robust and only tested on my win10 pro box so I’ll leave it for your comments before starting a pull request. By the way this is done by directly modifying upgrade/index.js in yarn global bin directory. I guess there’s no test case around upgrade feature in the generator project?

Interesting, this line looks suspicious to me :

generatorCommand = this.clientPackageManager === 'yarn' ? '$(yarn bin)/jhipster' : '$(npm bin)/jhipster';

It can be expanded only in a unix shell and as shelljs.exec uses cmd.exe, it’s normal that it fails $(yarn bin)/jhipster --with-entities --force --skip-install ....

So this bug affects all Windows users whatever shell they use.

The fix should be to use shelljs to execute yarn bin or npm bin and capture output to set generatorCommand’s value.

I’ll work on it in few hours unless you want to do it in meantime @iconben