Installed an older project on my new Ubuntu, of course got some compile errors after updating typescript and most i could revolve by changing my code. But this one I don't know how to get rid of:
Error
node_modules/@types/node/index.d.ts:995:14 - error TS2484: Export declaration conflicts with exported declaration of 'Buffer'.
typescript: 3.0.1
node: 10.7.0
ts-config:
{
"compilerOptions": {
"outDir": "./dist/", // path to output directory
"sourceMap": true, // allow sourcemap support
"module": "commonjs",
"noImplicitAny": false,
"strictNullChecks": true, // enable strict null checks as a best practice
"target": "esnext", // specify ECMAScript target version
"allowJs": true, // allow a partial TypeScript and JavaScript codebase
"baseUrl": ".",
"lib":["esnext","esnext.asynciterable"],
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
}
},
"exclude": [
"node_modules"
],
"include": [
"./src/**/*",
"./src/page/data",
"./src/**/mustache",
]
}
I can not get this error locally just using latest @types\node. Can you share more context? If i were to guess there is another @types package that you are using that is augmenting the declarations in @types/node.
same issue here.
the @types/node declaration seems to conflict with that from the buffer module that browserify uses.
not yet sure what to do about it.
@smcatala can you share more information about your setup. i can not reproduce this with @types/node + @types/browserify
@mhegazy, sure: browserify transpiles the source code using the tsify plugin. @types/browserify is not installed.
browserify depends on buffer@^5.0.2, which does not include type declarations, but npm typically installs 5.2.0 instead (semver compatible), which does:
a type declaration file was added to that version of the buffer module.
according to VScode, in line 977 of @types/node/index.d.ts (var BuffType: typeof Buffer), Buffer refers to both the definition from @types/node/index.d.ts as well as that from the buffer/index.d.ts file.
Having this same problem. To repro, try installing "buffer" and also "@types/buffer". Is there any way to hide a module declaration from the main repo?
a potential workaround for this issue if your project is using package-lock.json is to npm install [email protected]. this works here, but I guess it depends on which modules in your project depend on which version of buffer...
thanks for the info. i can reproduce this locally now.
this is a bug in the declaration file of buffer. using ambient module declarations (declare module "buffer") adds the declaration in the global namespace, which then merges with existing declarations for the global node module "buffer", and hence the error.
the declaration file in buffer should rather use the module syntax:
export class Buffer extends Uint8Array {
...
}
instead of:
declare module 'buffer' {
export class Buffer extends Uint8Array {
....
}
}
I would recommend filing this issue under https://github.com/feross/buffer/issues instead.
To override the declaration of buffer, you can add a local file with the contents of node_modules\buffer\index.d.ts with the changes suggessted in my erlier comment, then add a "paths" mapping entry for it in your tsconfig.jon:
{
"compilerOptions": {
...
"baseUrl": "./",
"paths": { "buffer" : ["./buffer-override.d.ts"] }
}
}
Looks like this is already tracked by https://github.com/feross/buffer/issues/213
Thanks a lot everyone for the fast response, its my second project with TS so that was beyond my understanding.
Sorry for the slight hijack but I'm having trouble using this in an includes, excludes context. @mhegazy I followed your suggestion exactly but when I try to specify files manually, I run into trouble with Cannot find name 'Buffer in some dependent libraries.. Here is my tsconfig.json:
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"lib": ["es2015"],
"declaration": true,
"outDir": "./dist",
"strict": true,
"baseUrl": "./",
"paths": {
"buffer": ["./types/buffer-override.d.ts"]
},
"typeRoots": [
"node_modules/ethers/dist/types",
"node_modules/@0xproject/typescript-typings/types"
],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
},
"include": [
"types/**/*",
"utils/**/*",
],
"exclude": [
"test/**/*",
"node_modules"
]
}
My buffer-override.d.ts is located in types/buffer-override.d.ts as in paths. If I remove the includes and excludes sections, there are no issues, but I want to remove my /test folder from the output files.
Any ideas? :confused:
Thanks
This issue has been marked as external or unactionable and has seen no activity in the last day. It has been closed for automatic house-keeping purposes.
Most helpful comment
To override the declaration of
buffer, you can add a local file with the contents ofnode_modules\buffer\index.d.tswith the changes suggessted in my erlier comment, then add a"paths"mapping entry for it in your tsconfig.jon: