Ionic-app-scripts: Typescript transpile fails - Node typings ignored

Created on 5 Sep 2017  路  1Comment  路  Source: ionic-team/ionic-app-scripts

Note: for support questions, please use one of these channels:

https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/

Short description of the problem:

I added a library (TypeORM) to my ionic app and installed typings for node via npm install @types/node since they are required for this library. When running ionic-app-scripts build the transpile fails because it doesn't know about Buffer. When running tsc directly no errors are given.
I tried including the types in the tsconfig.json file, but that didn't change the output.

What behavior are you expecting?

It should find and use the Node typings in node_modules/@types/node

Steps to reproduce:

  1. Create a new Ionic app
  2. npm install @types/node
  3. Clone and compile typeorm (the most recent changed aren't yet released, but needed)
  4. Copy everything from build/browser/typeorm info node_modules/typeorm
  5. Create a connection in app.component.ts:
constructor() {
    createConnection({
      type: "websql",
      database: "test",
      entities: [
        User
      ],
      autoSchemaSync: true,
      logging: true
    }).then(connection => {
      console.log("Database loaded");
    }).catch(error => {
      console.log(error);
    });
  }

Which @ionic/app-scripts version are you using?
2.1.4

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

[11:27:11]  transpile started ...
[11:27:18]  typescript: <path>/node_modules/typeorm/driver/mongodb/MongoConnectionOptions.ts, line: 54
            Cannot find name 'Buffer'.
      L54:      readonly sslCA?: string[]|Buffer[];

Forum post with more information

Most helpful comment

I added typeRoots to the tsconfig.json file but not in the compilerOptions.
This is the working tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

>All comments

I added typeRoots to the tsconfig.json file but not in the compilerOptions.
This is the working tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jgw96 picture jgw96  路  3Comments

brandyscarney picture brandyscarney  路  4Comments

danbucholtz picture danbucholtz  路  4Comments

barbsicle picture barbsicle  路  3Comments

danbucholtz picture danbucholtz  路  4Comments