Grpc-node: node_modules/grpc/index.d.ts - Imports are not permitted in module augmentations

Created on 22 Aug 2019  路  10Comments  路  Source: grpc/grpc-node

Problem description

Im using grpc with typescript but the typescript compile command fails with the following error: 'Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.'

Reproduction steps

Install grpc in node project with typescript. Add a file that imports grpc. run tsc -p tsconfig.json wirh target=es6 and module=commonjs.

Environment

  • macOS Mojave
  • Node version 11.10
  • Node installation method : nvm
  • If applicable, compiler version [e.g. clang 3.8.0-2ubuntu4]
  • Package name and version: gRPC@^1.23.2

Additional context

Add any other context about the problem here. If possible, attach full logs. Do not try to omit anything for brevity, but instead include absolutely everything. Please try and set your operating system's locale to English, so that logs contain error messages in the English language.

Most helpful comment

$ tsc -p tsconfig.json

node_modules/grpc/index.d.ts:21:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

21   import { Message, Service as ProtobufService } from "protobufjs";
     ~~~~~~

node_modules/grpc/index.d.ts:21:55 - error TS2307: Cannot find module 'protobufjs'.

21   import { Message, Service as ProtobufService } from "protobufjs";
                                                         ~~~~~~~~~~~~

node_modules/grpc/index.d.ts:22:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

22   import { Duplex, Readable, Writable } from "stream";
     ~~~~~~

node_modules/grpc/index.d.ts:23:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

23   import { SecureContext } from "tls";
     ~~~~~~


Found 4 errors.

$ cat tsconfig.json

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs"
  }
}

$ cat package.json

{
   ......(generated by npm init)

  "dependencies": {
    "grpc": "^1.23.2"
  },
  "devDependencies": {
    "@types/node": "^12.7.2"
  }
}

All 10 comments

Can you please include the full error output from running tsc?

$ tsc -p tsconfig.json

node_modules/grpc/index.d.ts:21:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

21   import { Message, Service as ProtobufService } from "protobufjs";
     ~~~~~~

node_modules/grpc/index.d.ts:21:55 - error TS2307: Cannot find module 'protobufjs'.

21   import { Message, Service as ProtobufService } from "protobufjs";
                                                         ~~~~~~~~~~~~

node_modules/grpc/index.d.ts:22:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

22   import { Duplex, Readable, Writable } from "stream";
     ~~~~~~

node_modules/grpc/index.d.ts:23:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

23   import { SecureContext } from "tls";
     ~~~~~~


Found 4 errors.

$ cat tsconfig.json

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs"
  }
}

$ cat package.json

{
   ......(generated by npm init)

  "dependencies": {
    "grpc": "^1.23.2"
  },
  "devDependencies": {
    "@types/node": "^12.7.2"
  }
}

I also experience this issue.

Here is my output:

[11:44:49 AM] Starting compilation in watch mode...

node_modules/.registry.npmjs.org/grpc/1.23.2/node_modules/grpc/index.d.ts:21:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

21   import { Message, Service as ProtobufService } from "protobufjs";
     ~~~~~~

node_modules/.registry.npmjs.org/grpc/1.23.2/node_modules/grpc/index.d.ts:21:55 - error TS2307: Cannot find module 'protobufjs'.

21   import { Message, Service as ProtobufService } from "protobufjs";
                                                         ~~~~~~~~~~~~

node_modules/.registry.npmjs.org/grpc/1.23.2/node_modules/grpc/index.d.ts:22:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

22   import { Duplex, Readable, Writable } from "stream";
     ~~~~~~

node_modules/.registry.npmjs.org/grpc/1.23.2/node_modules/grpc/index.d.ts:23:3 - error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.

23   import { SecureContext } from "tls";
     ~~~~~~

[11:44:51 AM] Found 4 errors. Watching for file changes.

I think it's not valid .d.ts. file because you can't use imports in declared module

Same here, I think that 1.23.2 broke the declaration file.

It looks like this actually broke in 1.22, but I can't tell why.

Update: I can reproduce this error if I install the package, but not if I use the package as it exists in the git repository.

I have a fix. https://github.com/grpc/grpc-node/pull/1002 added a reference to EventEmitter outside the declare module "grpc", but it should be inside.

Thank you for your help. I should be able to publish a patch release with that fix today or tomorrow.

I have published version 1.23.3 with that fix.

That fix probably got dropped in 1.24.0 but it should be back in 1.24.1.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

polRk picture polRk  路  3Comments

Aswathi17 picture Aswathi17  路  3Comments

shotor picture shotor  路  3Comments

samuela picture samuela  路  4Comments

respinha picture respinha  路  6Comments