jhipster / generator-jhipster-nodejs

A NodeJS blueprint that creates the backend using NestJS
https://www.npmjs.com/package/generator-jhipster-nodejs
Apache License 2.0
257 stars 80 forks source link

Unable to start njhipster docker generated application code - src/client/header-util.ts(54,15): error TS2552: Cannot find name 'URL'. Did you mean 'url'? #267

Closed ranraj closed 11 months ago

ranraj commented 2 years ago

Describe the bug src/client/header-util.ts(54,15): error TS2552: Cannot find name 'URL'. Did you mean 'url'? Getting this error during docker run of njhipster generated nodejs server code.

To Reproduce Steps to reproduce the behaviour:

wget https://github.com/jhipster/generator-jhipster-nodejs/raw/master/docker/Dockerfile
docker build -t jhipster-generator-nodejs:latest .
docker run -it --rm -v $PWD:/home/jhipster/app jhipster-generator-nodejs jhipster --blueprints nodejs
docker build . -t node-app-jhipster:latest
docker run node-app-jhipster:latest

Exception log

> app@0.0.1 copy-resources /usr/node-app/server
> ts-node scripts/copy-resources.ts

[nodemon] 1.19.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /usr/node-app/server/src/**/*
[nodemon] starting `ts-node src/main.ts`
[Nest] 223   - 03/24/2022, 4:14:35 AM   [Config] Actual process.env.BACKEND_ENV value: dev
[Nest] 223   - 03/24/2022, 4:14:35 AM   [Config] Standard allowed values are: dev, test or prod
[Nest] 223   - 03/24/2022, 4:14:35 AM   [Config] if you run with a non standard BACKEND_ENV value, remember to add your application-{process.env.BACKEND_ENV}.yml file

/usr/node-app/server/node_modules/ts-node/src/index.ts:240
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/client/header-util.ts(56,15): error TS2552: Cannot find name 'URL'. Did you mean 'url'?

    at createTSError (/usr/node-app/server/node_modules/ts-node/src/index.ts:240:12)
    at reportTSError (/usr/node-app/server/node_modules/ts-node/src/index.ts:244:19)
    at getOutput (/usr/node-app/server/node_modules/ts-node/src/index.ts:360:34)
    at Object.compile (/usr/node-app/server/node_modules/ts-node/src/index.ts:393:11)
    at Module.m._compile (/usr/node-app/server/node_modules/ts-node/src/index.ts:439:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (/usr/node-app/server/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
[nodemon] app crashed - waiting for file changes before starting...

Expected behavior Expected basic nodejs application up and running from the docker container.

Screenshots If applicable, add screenshots to help explain your problem.

Screenshot 2022-03-24 at 8 48 27 AM

Desktop (please complete the following information):

NHipster configuration

docker run -it --rm -v $PWD:/home/jhipster/app jhipster-generator-nodejs jhipster info INFO! Using JHipster version installed locally in current project's node_modules INFO! No custom sharedOptions found within blueprint: generator-jhipster-nodejs at /home/jhipster/app/node_modules/generator-jhipster-nodejs INFO! No custom commands found within blueprint: generator-jhipster-nodejs at /home/jhipster/app/node_modules/generator-jhipster-nodejs Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
app@0.0.1-SNAPSHOT /home/jhipster/app
+-- generator-jhipster-nodejs@2.0.0
| `-- generator-jhipster@7.0.1 deduped
`-- generator-jhipster@7.0.1
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "blueprints": [
      {
        "name": "generator-jhipster-nodejs",
        "version": "2.0.0"
      }
    ],
    "otherModules": [
      {
        "name": "generator-jhipster-nodejs",
        "version": "2.0.0"
      }
    ],
    "applicationType": "monolith",
    "baseName": "app",
    "jhipsterVersion": "7.0.1",
    "skipClient": false,
    "skipServer": false,
    "skipUserManagement": false,
    "skipCheckLengthOfIdentifier": false,
    "skipFakeData": false,
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "testFrameworks": [],
    "pages": [],
    "creationTimestamp": 1648091633565,
    "serverPort": "8081",
    "packageName": "com.jhipster.node",
    "databaseType": "sql",
    "devDatabaseType": "sqlite",
    "prodDatabaseType": "mysql",
    "authenticationType": "jwt",
    "clientFramework": "angularX",
    "withAdminUi": true,
    "clientTheme": "none",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "packageFolder": "com/jhipster/node",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "serviceDiscoveryType": false,
    "websocket": false,
    "searchEngine": false,
    "messageBroker": false,
    "clientPackageManager": "npm",
    "clientThemeVariant": "",
    "languages": ["en"],
    "cacheProvider": "ehcache",
    "buildTool": "maven",
    "enableHibernateCache": true,
    "reactive": false
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

Environment and Tools

node: v14.16.0

npm: 8.5.5

No change to package.json was detected. No package manager install will be executed. Congratulations, JHipster execution is complete! Sponsored with ❤️ by @oktadev.

Additional context Add any other context about the problem here.

ranraj commented 2 years ago

I have seen one bug already reported https://github.com/jhipster/generator-jhipster-nodejs/issues/258 But It seems the changes proposed by @amanganiello90 has already been present in the current version.

https://github.com/jhipster/generator-jhipster-nodejs/blob/7002525011ef61db674ea8997a7dabf7fdd497ec/docker/Dockerfile#L17

ghacupha commented 2 years ago

Yea noticed that too. According to this answer on StackOverflow, you are supposed to add "dom" to the lib property of the compiler options, in the server's tsconfig.json file to enable the dom typings in the app, since the URL interface is declared in that typing file (lib.dom.d.ts) and used for creating object URLs.

easyservices commented 2 years ago

Yea noticed that too. According to this answer on StackOverflow, you are supposed to add "dom" to the lib property of the compiler options, in the server's tsconfig.json file to enable the dom typings in the app, since the URL interface is declared in that typing file (lib.dom.d.ts) and used for creating object URLs.

No it is not the issue as it is already there in the last version. The solution is to simply to add the followings:

import { URL } from 'url';

in the /server/src/client/header-util.ts file.

danielbrutti commented 2 years ago

Hello, I agree with @easyservices

I have a new project, "dom" is on lib property of the tsconfig, and the import issue is there.

Adding the import { URL } from 'url'; fix the issue.