Skip to content

Build failing on a fresh install #2986

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

Closed
Kabangi opened this issue May 29, 2019 · 10 comments
Closed

Build failing on a fresh install #2986

Kabangi opened this issue May 29, 2019 · 10 comments
Assignees

Comments

@Kabangi
Copy link

Kabangi commented May 29, 2019

Steps to reproduce.

  1. Install @loopback packages all latest versions
  2. Create a new project
  3. Add a persistent model
  4. Build the project
  5. Observe the build fails with typescript errors
src/controllers/test.controller.ts:69:43 - error TS2345: Argument of type 'Filter<AnyObject> | undefined' is not assignable to parameter of type 'Filter<Test> | undefined'.
  Type 'Filter<AnyObject>' is not assignable to type 'Filter<Test>'.
    Type 'AnyObject' is missing the following properties from type 'Test': id, getId, getIdObject, toJSON, toObject

69     return await this.testRepository.find(filter);
@Kabangi Kabangi changed the title Build failing on latest on version 1.4 Build failing on version 1.4 May 29, 2019
@Kabangi
Copy link
Author

Kabangi commented May 29, 2019

Related to this #2973

@raymondfeng
Copy link
Contributor

@Kabangi Which package is version 1.4?

@Kabangi
Copy link
Author

Kabangi commented May 30, 2019

Here are the dependencies

{
  "name": "testprod",
  "version": "1.0.0",
  "description": "testprod",
  "keywords": [
    "loopback-application",
    "loopback"
  ],
  "main": "index.js",
  "engines": {
    "node": ">=8.9"
  },
  "scripts": {
    "build:apidocs": "lb-apidocs",
    "build": "lb-tsc es2017 --outDir dist",
    "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/__tests__\"",
    "posttest": "npm run lint",
    "test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
    "docker:build": "docker build -t testprod .",
    "docker:run": "docker run -p 3000:3000 -d testprod",
    "migrate": "node ./dist/migrate",
    "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",
    "!*/__tests__"
  ],
  "dependencies": {
    "@loopback/boot": "^1.2.8",
    "@loopback/context": "^1.16.0",
    "@loopback/core": "^1.7.1",
    "@loopback/openapi-v3": "^1.4.0",
    "@loopback/repository": "^1.5.6",
    "@loopback/rest": "^1.12.0",
    "@loopback/rest-explorer": "^1.1.23",
    "@loopback/service-proxy": "^1.1.11",
    "loopback-connector-mysql": "^5.4.1"
  },
  "devDependencies": {
    "@loopback/build": "^1.5.5",
    "@loopback/testlab": "^1.2.10",
    "@loopback/tslint-config": "^2.0.4",
    "@types/node": "^10.11.2",
    "tslint": "^5.15.0",
    "typescript": "^3.4.3"
  }
}

@Kabangi Kabangi changed the title Build failing on version 1.4 Build failing on a fresh install May 30, 2019
@leotj
Copy link

leotj commented May 30, 2019

@raymondfeng I face this problem too when trying to build loopback4-example-todo-list.

@dhmlau
Copy link
Member

dhmlau commented May 30, 2019

I was able to rerproduce with the todo-list example. Here are the steps to reproduce:

$ npm i -g @loopback/cli     <--- to make sure i'm on the latest
$ lb4 example todo-list        <---- get the todo-list example
$ cd loopback4-example-todo-list
$ npm i
$ npm run build

Here are a few errors I got:

$ npm run build

> @loopback/[email protected] build /Users/dianalau/loopback4-example2/loopback4-example-todo-list
> lb-tsc es2017 --outDir dist

src/__tests__/unit/controllers/todo-list-todo.controller.unit.ts:158:7 - error TS2322: Type 'SinonStub<[DataObject<Todo>, (AnyObject | undefined)?], Promise<Todo>>' is not assignable to type 'SinonStub<any[], any>'.
  Property '0' is missing in type 'any[]' but required in type '[DataObject<Todo>, (AnyObject | undefined)?]'.

158     ({create, find, patch, delete: del} = constrainedTodoRepo.stubs);
          ~~~~~~

src/__tests__/unit/controllers/todo-list-todo.controller.unit.ts:158:15 - error TS2322: Type 'SinonStub<[(Filter<Todo> | undefined)?, (AnyObject | undefined)?], Promise<Todo[]>>' is not assignable to type 'SinonStub<any[], any>'.
  Type 'any[]' is not assignable to type '[(Filter<Todo> | undefined)?, (AnyObject | undefined)?]'.
    Types of property 'length' are incompatible.
      Type 'number' is not assignable to type '0 | 1 | 2'.

158     ({create, find, patch, delete: del} = constrainedTodoRepo.stubs);
                  ~~~~

@raymondfeng
Copy link
Contributor

It's broken by TypeScript 3.5. We have fixed it with #2996.

In your case, please check "typescript": "^3.4.3" to be `"typescript": "~3.4.3".

@raymondfeng
Copy link
Contributor

For loopback-next, we probably should change TypeScript dependencies to use ~ instead of ^ as minor versions of TypeScript often have breaking changes.

@dhmlau
Copy link
Member

dhmlau commented May 30, 2019

Thank @raymondfeng. It's working for now after changing the package.json to what @raymondfeng suggested above, deleting package-lock.json and rebuilding again.

@leotj
Copy link

leotj commented May 30, 2019

Thank you @raymondfeng. It's working now.

@bajtos
Copy link
Member

bajtos commented May 31, 2019

For loopback-next, we probably should change TypeScript dependencies to use ~ instead of ^ as minor versions of TypeScript often have breaking changes.

Please note that scaffolded projects don't control the TypeScript version, it's controlled by @loopback/build's package.json. If we change TypeScript dependency to ~, then we will have to publish a new version of @loopback/build whenever a new version of TypeScript is published, plus scaffolded projects would have to use ~ for @loopback/build.

Personally, I'd prefer a different solution: include package-lock.json in newly created projects. That way we can fixate the TypeScript version that's installed by npm while leaving control of the TypeScript version in user hands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants