0

So I have an existing typescript/node project which runs and builds fine but when I tried to add inversify to the project using this guide https://medium.com/tkssharma/dependency-injection-setting-up-inversifyjs-ioc-for-typescript-apps-da65edfb1ea8 it seems to be breaking the build completely.

Here is my tsconfig.json file

{
  "compilerOptions": {
  "module": "commonjs",
  "declaration": true,
  "removeComments": true,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "target": "es5",
  "lib": ["es6","dom"],
  "types": ["reflect-metadata"],
  "moduleResolution": "node",
  "sourceMap": true,
  "outDir": "./dist",
  "baseUrl": "./",
  "incremental": true
},
"include": ["src/**/*", "src/client/main.ts"],
"exclude": ["node_modules", "dist"]
}

When I run npm run bundle/build on the project, after I added the inversify specific stuff, some basic stuff is starting to break like the following

src/main.ts:1:21 - error TS2307: Cannot find module 'fs' or its corresponding type declarations.

1 import * as fs from 'fs';
                  ~~~~

src/main.ts:2:23 - error TS2307: Cannot find module 'util' or its corresponding type declarations.

2 import * as util from 'util';
                    ~~~~~~

src/main.ts:3:25 - error TS2307: Cannot find module 'crypto' or its corresponding type declarations.

3 import * as crypto from 'crypto';
                      ~~~~~~~~
p0tta
  • 1,461
  • 6
  • 28
  • 49

1 Answers1

0

I faced the same issue. You can solve it like this:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "lib": ["es6","dom"],
    "types": ["node", "reflect-metadata"],
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  },
  "include": ["src/**/*", "src/client/main.ts"],
  "exclude": ["node_modules", "dist"]
}

You need to include the node's types in the types definition.

...
"types": ["node", "reflect-metadata"],
...

I hope you find this useful, and also others that deal with the same issue.

Best,

fkone
  • 1
  • 2