Loopback-next: Unexpected failure (compilation error with fully generated code by lb4)

Created on 1 Oct 2018  Â·  11Comments  Â·  Source: strongloop/loopback-next

Description / Steps to reproduce / Feature proposal

Note: I posted this on Friday on the LoopbackJS forum but it was most probably no good idea :-(

Current Behavior

Having used (and appreciated StrongLoop/Loopback with sucess in the past, it's with delight that I have learned that Loopback 4 played the Typescript card and adopted other welcome technologies. So I'm giving it a try (while taking into account that it's not production-ready yet).

Unfortunately, I'm already stumbiing on the 2 fairly annoying difficulties (the one mentioned here and another one mentioned in a second forthcoming post, related to repositories/datasources).

The problem experienced here is fairly easy to reproduce: I use loopback-cli to scaffold a new (test) application and I already experience a failure when just applying the cli's instructions (namely: cd ; npm start.

Below the transcript of the session:

alain@aegnor:~/devel/strongloop$ lb4 app lb4test2 --tslint --prettier --mocha --loopbackBuild --vscode
? Project description: lb4test2
? Project root directory: lb-4-test-2
? Application class name: Lb4test2Application
? Select features to enable in the project Enable repositories, Enable services
create .npmrc
create .prettierignore
create .prettierrc
create DEVELOPING.md
create README.md
create index.ts
create package.json
create tsconfig.json
create tslint.build.json
create tslint.json
create .vscode/settings.json
create .vscode/tasks.json
create test/mocha.opts
create .gitignore
create index.js
create public/index.html
create src/application.ts
create src/index.ts
create src/sequence.ts
create test/README.md
create src/controllers/README.md
create src/controllers/home-page.controller.ts
create src/controllers/index.ts
create src/controllers/ping.controller.ts
create src/datasources/README.md
create src/models/README.md
create src/repositories/README.md
create test/acceptance/home-page.controller.acceptance.ts
create test/acceptance/ping.controller.acceptance.ts
create test/acceptance/test-helper.ts
npm WARN [email protected] No license field.

added 550 packages from 1361 contributors and audited 2691 packages in 9.925s
found 1 low severity vulnerability
run npm audit fix to fix them, or npm audit for details

Application lb4test2 was created in lb-4-test-2.

Next steps:

$ cd lb-4-test-2

$ npm start

alain@aegnor:~/devel/strongloop/lb-4-test-2$ npm start

[email protected] prestart /media/elrond_2tb/devel/strongloop/lb-4-test-2
npm run build

[email protected] build /media/elrond_2tb/devel/strongloop/lb-4-test-2
lb-tsc

node_modules/@loopback/context/dist8/src/binding-key.d.ts:5:42 - error TS1039: Initializers are not allowed in ambient contexts.

5 static readonly PROPERTY_SEPARATOR = "#";
~~~

node_modules/@loopback/repository/dist8/src/types/any.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "any";
~

node_modules/@loopback/repository/dist8/src/types/array.d.ts:8:21 - error TS1039: Initializers are not allowed in ambient contexts.

8 readonly name = "array";
~~~

node_modules/@loopback/repository/dist8/src/types/boolean.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "boolean";
~~~~~

node_modules/@loopback/repository/dist8/src/types/buffer.d.ts:8:21 - error TS1039: Initializers are not allowed in ambient contexts.

8 readonly name = "buffer";
~~~~

node_modules/@loopback/repository/dist8/src/types/date.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "date";
~~

node_modules/@loopback/repository/dist8/src/types/number.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "number";
~~~~

node_modules/@loopback/repository/dist8/src/types/string.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "string";
~~~~

node_modules/@loopback/repository/dist8/src/types/union.d.ts:8:21 - error TS1039: Initializers are not allowed in ambient contexts.

8 readonly name = "union";
~~~

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: lb-tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/alain/.npm/_logs/2018-09-29T20_30_26_921Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] prestart: npm run build
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/alain/.npm/_logs/2018-09-29T20_30_26_952Z-debug.log

Expected Behavior

For such a trivial example (a few Loopback CLI commands), one expects no compilation error. (Note: I'm experimenting with LB4 with less intensive use of scaffolding and it's working better (to some extent); so, this is certainly just a glitch.

Can somebody help? (Or should I log this as a potential bug?) (I'm running the latest version of node, namely 10.0.0 and had just upgraded loopback-cli to v. 0.27).

Thanks in advance,
Alain

All 11 comments

hi @koalabi , I just ran the sequence commands you specified and got it working with no problems. Could you please share what version of node JS is installed in your environment and the current version of lb4 CLI?

Here is mine, with node

# node --version
v9.5.0

# lb4 --version
@loopback/cli version: 0.27.0

@loopback/* dependencies:
  - @loopback/authentication: ^0.11.17
  - @loopback/boot: ^0.14.3
  - @loopback/build: ^0.7.4
  - @loopback/context: ^0.12.13
  - @loopback/core: ^0.11.14
  - @loopback/metadata: ^0.9.12
  - @loopback/openapi-spec-builder: ^0.9.3
  - @loopback/openapi-v3-types: ^0.9.5
  - @loopback/openapi-v3: ^0.15.2
  - @loopback/repository-json-schema: ^0.11.2
  - @loopback/repository: ^0.19.0
  - @loopback/rest: ^0.25.2
  - @loopback/testlab: ^0.14.1
  - @loopback/docs: ^0.22.0
  - @loopback/example-hello-world: ^0.10.3
  - @loopback/example-log-extension: ^0.11.17
  - @loopback/example-rpc-server: ^0.11.11
  - @loopback/example-todo: ^0.20.2
  - @loopback/example-soap-calculator: ^0.4.3
  - @loopback/dist-util: ^0.3.7
  - @loopback/service-proxy: ^0.8.8
  - @loopback/http-caching-proxy: ^0.3.11
  - @loopback/http-server: ^0.4.3
  - @loopback/example-todo-list: ^0.7.0

I am confirming that even with node 10.0.0 it is working for me. FYI, My tsc --version is 2.8.1.

screen shot 2018-10-01 at 01 30 19

Thanks for asking ;-) (really)

The versions are as follows:

  • Node.js : 10.0.0
  • loopback-cli: 0.29 (just upgraded before experiencing failure :-( )
  • tsc (not sure that lb4 doesn't impose one; otherwise my default
    TypeScript compiler is up-to-date - I have no access to my system right now
    but I can provide the precise version number this evening)

And I didn't type any other commands than the ones shown. I will try once
more from scratch and let you know the outcome.

Thanks for the support, anyway.

Kind regards,

Alain

On Mon, Oct 1, 2018 at 8:37 AM Mario Estrada notifications@github.com
wrote:

hi @koalabi https://github.com/koalabi , I just ran the sequence
commands you specified and got it working with no problems. Could you
please share what version of node JS is installed in your environment and
the current version of lb4 CLI?

Here is mine, with node

node --version

v9.5.0

lb4 --version

@loopback/cli version: 0.27.0

@loopback/* dependencies:

  • @loopback/authentication: ^0.11.17
  • @loopback/boot: ^0.14.3
  • @loopback/build: ^0.7.4
  • @loopback/context: ^0.12.13
  • @loopback/core: ^0.11.14
  • @loopback/metadata: ^0.9.12
  • @loopback/openapi-spec-builder: ^0.9.3
  • @loopback/openapi-v3-types: ^0.9.5
  • @loopback/openapi-v3: ^0.15.2
  • @loopback/repository-json-schema: ^0.11.2
  • @loopback/repository: ^0.19.0
  • @loopback/rest: ^0.25.2
  • @loopback/testlab: ^0.14.1
  • @loopback/docs: ^0.22.0
  • @loopback/example-hello-world: ^0.10.3
  • @loopback/example-log-extension: ^0.11.17
  • @loopback/example-rpc-server: ^0.11.11
  • @loopback/example-todo: ^0.20.2
  • @loopback/example-soap-calculator: ^0.4.3
  • @loopback/dist-util: ^0.3.7
  • @loopback/service-proxy: ^0.8.8
  • @loopback/http-caching-proxy: ^0.3.11
  • @loopback/http-server: ^0.4.3
  • @loopback/example-todo-list: ^0.7.0

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/strongloop/loopback-next/issues/1783#issuecomment-425803624,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACqwzaRe4clzyk--2HfYQnriaRFuz5nVks5ugbg0gaJpZM4XBcHb
.

for typescript, as given on stack overflow at least 2.1 is recommended for not to get this error. I also tried the steps & getting same error.
after upgrading to loopback-cli version 0.27 This issue is gone

FYI: Your global version of TypeScript does not matter. Each scaffolded app has a local dev dependency of compatible version of TypeScript

Sorry to spoil the party (and thanks to those who have answered so far) but I find it a bit rude to close the issue while I had mentioned that I would check this evening and provide feedback.

I have now checked again ... and the problem is still there:

alain@aegnor:~/devel/strongloop$ node -v
v10.0.0
alain@aegnor:~/devel/strongloop$ tsc -v
Version 2.8.3
alain@aegnor:~/devel/strongloop$ lb4 -v
@loopback/cli version: 0.27.0

@loopback/* dependencies:

  • @loopback/authentication: ^0.11.17
  • @loopback/boot: ^0.14.3
  • @loopback/build: ^0.7.4
  • @loopback/context: ^0.12.13
  • @loopback/core: ^0.11.14
  • @loopback/metadata: ^0.9.12
  • @loopback/openapi-spec-builder: ^0.9.3
  • @loopback/openapi-v3-types: ^0.9.5
  • @loopback/openapi-v3: ^0.15.2
  • @loopback/repository-json-schema: ^0.11.2
  • @loopback/repository: ^0.19.0
  • @loopback/rest: ^0.25.2
  • @loopback/testlab: ^0.14.1
  • @loopback/docs: ^0.22.0
  • @loopback/example-hello-world: ^0.10.3
  • @loopback/example-log-extension: ^0.11.17
  • @loopback/example-rpc-server: ^0.11.11
  • @loopback/example-todo: ^0.20.2
  • @loopback/example-soap-calculator: ^0.4.3
  • @loopback/dist-util: ^0.3.7
  • @loopback/service-proxy: ^0.8.8
  • @loopback/http-caching-proxy: ^0.3.11
  • @loopback/http-server: ^0.4.3
  • @loopback/example-todo-list: ^0.7.0
    alain@aegnor:~/devel/strongloop$ lb4 app lb4test3 --tslint --prettier --mocha --loopbackBuild --vscode
    ? Project description: lb4test3
    ? Project root directory: lb-4-test-3
    ? Application class name: Lb4test3Application
    ? Select features to enable in the project Enable repositories, Enable services
    create .npmrc
    create .prettierignore
    create .prettierrc
    create DEVELOPING.md
    create README.md
    create index.ts
    create package.json
    create tsconfig.json
    create tslint.build.json
    create tslint.json
    create .vscode/settings.json
    create .vscode/tasks.json
    create test/mocha.opts
    create .gitignore
    create index.js
    create public/index.html
    create src/application.ts
    create src/index.ts
    create src/sequence.ts
    create test/README.md
    create src/controllers/README.md
    create src/controllers/home-page.controller.ts
    create src/controllers/index.ts
    create src/controllers/ping.controller.ts
    create src/datasources/README.md
    create src/models/README.md
    create src/repositories/README.md
    create test/acceptance/home-page.controller.acceptance.ts
    create test/acceptance/ping.controller.acceptance.ts
    create test/acceptance/test-helper.ts
    npm WARN [email protected] No license field.

added 550 packages from 1361 contributors and audited 2691 packages in 7.608s
found 1 low severity vulnerability
run npm audit fix to fix them, or npm audit for details

Application lb4test3 was created in lb-4-test-3.

Next steps:

$ cd lb-4-test-3
$ npm start

alain@aegnor:~/devel/strongloop$ cd lb-4-test-3
alain@aegnor:~/devel/strongloop/lb-4-test-3$ npm start

[email protected] prestart /media/elrond_2tb/devel/strongloop/lb-4-test-3
npm run build

[email protected] build /media/elrond_2tb/devel/strongloop/lb-4-test-3
lb-tsc

node_modules/@loopback/context/dist8/src/binding-key.d.ts:5:42 - error TS1039: Initializers are not allowed in ambient contexts.

5 static readonly PROPERTY_SEPARATOR = "#";
~~~

node_modules/@loopback/repository/dist8/src/types/any.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "any";
~

node_modules/@loopback/repository/dist8/src/types/array.d.ts:8:21 - error TS1039: Initializers are not allowed in ambient contexts.

8 readonly name = "array";
~~~

node_modules/@loopback/repository/dist8/src/types/boolean.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "boolean";
~~~~~

node_modules/@loopback/repository/dist8/src/types/buffer.d.ts:8:21 - error TS1039: Initializers are not allowed in ambient contexts.

8 readonly name = "buffer";
~~~~

node_modules/@loopback/repository/dist8/src/types/date.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "date";
~~

node_modules/@loopback/repository/dist8/src/types/number.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "number";
~~~~

node_modules/@loopback/repository/dist8/src/types/string.d.ts:6:21 - error TS1039: Initializers are not allowed in ambient contexts.

6 readonly name = "string";
~~~~

node_modules/@loopback/repository/dist8/src/types/union.d.ts:8:21 - error TS1039: Initializers are not allowed in ambient contexts.

8 readonly name = "union";
~~~

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: lb-tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/alain/.npm/_logs/2018-10-01T17_55_58_442Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] prestart: npm run build
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/alain/.npm/_logs/2018-10-01T17_55_58_468Z-debug.log

Below the generated package.json and tsconfig.json files.

=== package.json ===
{
"name": "lb4test3",
"version": "1.0.0",
"description": "lb4test3",
"keywords": [
"loopback-application",
"loopback"
],
"main": "index.js",
"engines": {
"node": ">=8.9"
},
"scripts": {
"build:all-dist": "npm run build:dist8 && npm run build:dist10",
"build:apidocs": "lb-apidocs",
"build": "lb-tsc",
"build:dist8": "lb-tsc es2017",
"build:dist10": "lb-tsc es2018",
"build:watch": "lb-tsc --watch",
"clean": "lb-clean dist",
"lint": "npm run prettier:check && npm run tslint",
"lint:fix": "npm run tslint:fix && npm run prettier:fix",
"prettier:cli": "lb-prettier \"/
.ts\" \"/.js\"",
"prettier:check": "npm run prettier:cli -- -l",
"prettier:fix": "npm run prettier:cli -- --write",
"tslint": "lb-tslint",
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run clean && npm run build",
"test": "lb-mocha --allow-console-logs \"DIST/test\"",
"posttest": "npm run lint",
"test:dev": "lb-mocha --allow-console-logs DIST/test/
/.js && npm run posttest",
"prestart": "npm run build",
"start": "node .",
"prepublishOnly": "npm run test"
},
"repository": {
"type": "git"
},
"author": "",
"license": "",
"files": [
"README.md",
"index.js",
"index.d.ts",
"dist/src",
"dist
/index*",
"src"
],
"dependencies": {
"@loopback/boot": "^0.14.3",
"@loopback/context": "^0.12.13",
"@loopback/core": "^0.11.14",
"@loopback/dist-util": "^0.3.7",
"@loopback/openapi-v3": "^0.15.2",
"@loopback/repository": "^0.19.0",
"@loopback/rest": "^0.25.2",
"@loopback/service-proxy": "^0.8.8"
},
"devDependencies": {
"@loopback/build": "^0.7.4",
"@loopback/testlab": "^0.14.1",
"@types/node": "^10.11.2"
}
}

=== tsconfig.json ===
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "./node_modules/@loopback/build/config/tsconfig.common.json",
"include": [
"src",
"test",
"index.ts"
],
"exclude": [
"node_modules/",
"packages//node_modules/
",
"
/.d.ts"
]
}

Hi @koalabi , please feel free to reopen the issue please. As for now, I have checked the same versions you had installed and as @raymondfeng said, it doesn't matter the current tsc version we might have globally installed, I will check and see if I can reproduce it.

Are you using NVM to manage the node version?. I ask to see if you check if you can reproduce it with 9.50 and the current 0.27 CLI version?: Sorry , final question, what OS are you using?.

Hi Mario,
Thanks for having taken the time to answer again. To answer your questions (I should have mentioned it indeed: I'm using Ubuntu 16.04LTS)

No, I'm not using NVM; just a plain Node.js installation (with npm, thus).

If this may serve: the skeleton application now works after I have done the following (based on similar problems reported on Internet for other frameworks:

alain@aegnor:\~/devel/strongloop/lb-4-test-5$ npm update tsc -g
alain@aegnor:\~ /devel/strongloop/lb-4-test-5$ hash -r
alain@aegnor:\~/devel/strongloop/lb-4-test-5$ tsc -v
Version 2.8.3
alain@aegnor:\~/devel/strongloop/lb-4-test-5$ rm -rf node_modules/
alain@aegnor:\~/devel/strongloop/lb-4-test-5$ npm install
npm WARN deprecated [email protected]: no longer maintained
npm WARN [email protected] No license field.

added 551 packages from 1361 contributors and audited 2691 packages in 13.504s
found 1 low severity vulnerability
run npm audit fix to fix them, or npm audit for details
alain@aegnor:~/devel/strongloop/lb-4-test-5$ npm start

[email protected] prestart /media/elrond_2tb/devel/strongloop/lb-4-test-5
npm run build

[email protected] build /media/elrond_2tb/devel/strongloop/lb-4-test-5
lb-tsc

[email protected] start /media/elrond_2tb/devel/strongloop/lb-4-test-5
node .

Server is running at http://[::1]:3000
Try http://[::1]:3000/ping
^C^C
alain@aegnor:\~/devel/strongloop/lb-4-test-5$ node -v
v10.0.0
alain@aegnor:\~/devel/strongloop/lb-4-test-5$ lb4 -v
@loopback/cli version: 0.27.0

@loopback/* dependencies:

  • @loopback/authentication: ^0.11.17
  • @loopback/boot: ^0.14.3
  • @loopback/build: ^0.7.4
  • @loopback/context: ^0.12.13
  • @loopback/core: ^0.11.14
  • @loopback/metadata: ^0.9.12
  • @loopback/openapi-spec-builder: ^0.9.3
  • @loopback/openapi-v3-types: ^0.9.5
  • @loopback/openapi-v3: ^0.15.2
  • @loopback/repository-json-schema: ^0.11.2
  • @loopback/repository: ^0.19.0
  • @loopback/rest: ^0.25.2
  • @loopback/testlab: ^0.14.1
  • @loopback/docs: ^0.22.0
  • @loopback/example-hello-world: ^0.10.3
  • @loopback/example-log-extension: ^0.11.17
  • @loopback/example-rpc-server: ^0.11.11
  • @loopback/example-todo: ^0.20.2
  • @loopback/example-soap-calculator: ^0.4.3
  • @loopback/dist-util: ^0.3.7
  • @loopback/service-proxy: ^0.8.8
  • @loopback/http-caching-proxy: ^0.3.11
  • @loopback/http-server: ^0.4.3
  • @loopback/example-todo-list: ^0.7.0

Go figure! :-( (just a "rm -rf node_modules/" and then a "npm install" again - there is a glitch somewhere)

@koalabi I closed the issue based @shatayuD comment:

I also tried the steps & getting same error.
after upgrading to loopback-cli version 0.27 This issue is gone

Feel free to reopen if you still have the issue.

@koalabi,
I think the previous update on the global tsc didn't have any impact. Probably your removal of node_modules and reinstall it did. However, to be cleared, it worked after doing this cleaning and reinstall of node_modules right?.

@marioestradarosa
Yes, I agree that update didn't have any impact (it was just to be sure and was before removing node_modules).

Yes, I confirm: after the rm -rf and reinstall, "npm start" ran fine and I got the skeleton app running. (I still wonder what the problem can be) Now for more explorations.

Thanks for your support and for the hard work. I think the move to TypeScript is really a plus (the more so as I'm actively promoting Angular as our corporate development framework).

My next step is to try connecting to MySQL via model/datasource/repositories (and then to add GraphQL and I think I will have the perfect stack for us). With loopback (2.x, I think) in the past it went very well. With loopback 4, I haven't had much luck so far.

Regards

Was this page helpful?
0 / 5 - 0 ratings