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.'
Install grpc in node project with typescript. Add a file that imports grpc. run tsc -p tsconfig.json wirh target=es6 and module=commonjs.
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.
Can you please include the full error output from running tsc?
$ tsc -p tsconfig.jsonnode_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.
Most helpful comment
$ tsc -p tsconfig.json$ cat tsconfig.json$ cat package.json