-
Notifications
You must be signed in to change notification settings - Fork 61
Typescript build error cjs #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi! Which version of |
This was the result:
|
I have a similar problem using yarn:
I can fix that if I install |
Closed due to inactivity, please reopen if needed. |
I've reencounted the same problem that @BenjaminPosselt described, so I'd like this isssue to be reopened. As context, I'm trying to convert an existing Node.js project with CommonJS modules into a project with ECMAScript Modules. My package.json: {
"name": "my_project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon --exec 'ts-node-esm' index.ts",
"build": "tsc --project ./"
},
"dependencies": {
"downloadjs": "^1.4.7",
"express": "^4.18.2",
"socket.io": "^4.6.1",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/express": "4.17.17",
"@types/node": "^18.16.7",
"@types/serve-static": "^1.15.1",
"@types/socket.io-parser": "^3.0.0",
"@types/ws": "^8.5.4",
"nodemon": "^2.0.22",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"optionalDependencies": {
... omitted
}
} My tsconfig.json: {
"compilerOptions": {
"target": "es6",
"module": "ES2022",
"moduleResolution": "node16",
//...
"outDir": "./build",
"esModuleInterop": true,
"strict": true
}
} Running the server with my_machine:~/my_project$ npm run build
> [email protected] build
> tsc --project ./
node_modules/engine.io/build/engine.io.d.ts:3:25 - error TS7016: Could not find a declaration file for module 'engine.io-parser'. '~/my_project/node_modules/engine.io-parser/build/cjs/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/engine.io-parser` if it exists or add a new declaration (.d.ts) file containing `declare module 'engine.io-parser';`
3 import * as parser from "engine.io-parser";
~~~~~~~~~~~~~~~~~~
node_modules/engine.io/build/socket.d.ts:5:25 - error TS7016: Could not find a declaration file for module 'engine.io-parser'. '~/my_project/node_modules/engine.io-parser/build/cjs/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/engine.io-parser` if it exists or add a new declaration (.d.ts) file containing `declare module 'engine.io-parser';`
5 import { RawData } from "engine.io-parser";
~~~~~~~~~~~~~~~~~~
node_modules/engine.io/build/transport.d.ts:4:24 - error TS7016: Could not find a declaration file for module 'engine.io-parser'. '~/my_project/node_modules/engine.io-parser/build/cjs/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/engine.io-parser` if it exists or add a new declaration (.d.ts) file containing `declare module 'engine.io-parser';`
4 import { Packet } from "engine.io-parser";
~~~~~~~~~~~~~~~~~~
Found 3 errors in 3 files.
Errors Files
1 node_modules/engine.io/build/engine.io.d.ts:3
1 node_modules/engine.io/build/socket.d.ts:5
1 node_modules/engine.io/build/transport.d.ts:4 Moving the .d.ts files into the cjs folder would fix the build process, but I don't want to do that for CI/CD. The engine.io-parser version my project uses: $ npm ls engine.io-parser
[email protected] ~/my_project
└─┬ [email protected]
└─┬ [email protected]
└── [email protected] |
The declaration files are now included for the CommonJS build: e4a1c2b Could you please check if that fixes the issue? |
It does fix the issue. Thank you! |
I just stumbled upon a weird error:
I am currently working on a typescript project which is using socket.io in its backend. (nodejs)
When trying to build it, I got this error:
When i tried copying the .d.ts files in your package from the esm folder into the cjs folder, it suddenly worked without complaint.
Could it be possible that you forgot to add the .d.ts files to the cjs export of your package or are my tsconfig configurations incorrect in some way?
Thank you! :)
The text was updated successfully, but these errors were encountered: