muratgozel / MIMEText

RFC-2822, RFC-2045 and RFC-2049 compliant raw email message generator.
https://muratgozel.github.io/MIMEText/
MIT License
82 stars 35 forks source link

Declaration file for module 'mimetext' is missing since v3.0.17 #62

Closed maplesteve closed 8 months ago

maplesteve commented 9 months ago

I import createMimeMessage

import {createMimeMessage} from 'mimetext'

It was working with v3.0.16. Starting with v3.0.17 the Typescript compiler yields an error:

Could not find a declaration file for module 'mimetext'. '[path]/node_modules/mimetext/dist/node/mimetext.cjs' implicitly has an 'any' type. Try npm i --save-dev @types/mimetext if it exists or add a new declaration (.d.ts) file containing declare module 'mimetext';ts(7016)

Last version tested: v3.0.20. It still yields the above error.

muratgozel commented 9 months ago

could you share your tsconfig please?

maplesteve commented 9 months ago

could you share your tsconfig please?

Sure.

{
  "compilerOptions": {
    "baseUrl": ".",
    "lib": ["ES2022"],
    "target": "ES2022",
    "module": "commonjs",
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noPropertyAccessFromIndexSignature": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedParameters": true,
    "noUnusedLocals": true,
    "paths": {
      "~/*": ["./src/*"],
      "@/*": ["./*"]
    },
    "sourceMap": true,
    "strict": true,
    "useDefineForClassFields": true
  },
  "include": ["./src", "./test/"]
}
muratgozel commented 9 months ago

i just realized, your typescript compiler still trying to import [path]/node_modules/mimetext/dist/node/mimetext.cjs from old path. the dist folder is not being used anymore (as of v3.0.17). its probably a caching issue with your typescript compiler or something else related your end. try to resolve it please, i don't know what to suggest without knowing your setup. i will be here to further assist in any case.

maplesteve commented 9 months ago

I'm sorry. The error message was from v3.0.17. Here's the one produced with v.3.0.20:

Could not find a declaration file for module 'mimetext'. '[path]/node_modules/mimetext/build/entrypoints/node.cjs' implicitly has an 'any' type. Try npm i --save-dev @types/mimetext if it exists or add a new declaration (.d.ts) file containing declare module 'mimetext';ts(7016)

muratgozel commented 9 months ago

okay :) which version of node.js and npm are you using? the types are defined in the same place where node.cjs is and your project should be able to find them by mimetext's package.json. it finds in my end, maybe related to the node.js version.

maplesteve commented 9 months ago

which version of node.js and npm are you using? the types are defined in the same place where node.cjs is and your project should be able to find them by mimetext's package.json. it finds in my end, maybe related to the node.js version.

Local v18.16.0/9.8.1 and the Github Action uses v18.19.0/10.2.3 - both builds are failing.

muratgozel commented 9 months ago

does your project's package.json has type: module?

maplesteve commented 9 months ago

does your project's package.json has type: module?

No, it's CommonJS. I think, that's why "/node_modules/mimetext/build/entrypoints/node.cjs" is used by the compiler; which seems correct. "Just" the typing can't be resolved.

muratgozel commented 9 months ago

exactly, usage of import syntax recognized by node only if package.json has type: module, otherwise require syntax should be used. mimetext load itself according to this principle.

maplesteve commented 9 months ago

exactly, usage of import syntax recognized by node only if package.json has type: module, otherwise require syntax should be used.

The import syntax does work perfectly; we us it all over the place in 80+ repos. Problem here is the typing. When I add "types": "./build/entrypoints/node.d.ts", to the package.json of the mimetext package, the compiler ist happy; no error.

muratgozel commented 9 months ago

as long as you use es imports without type:module in package.json, node won't be able to find types, let me see if there is anything i can do without breaking current workflow.

maplesteve commented 9 months ago

Thanks for looking into this.

as long as you use es imports without type:module in package.json, node won't be able to find types

This does not solve the typing problem. Also, it worked with mimetext up to v3.0.17. The typings cannot be resolved, because Node doesn't find the correct files.

IMO the solution would be to either

Maybe, this tool can help: https://arethetypeswrong.github.io/?p=mimetext%403.0.20

danielrhodes commented 9 months ago

@maplesteve Running into the same issue. Just pinned it to 3.0.17 to get around the issue and so I could move on... this definitely wasn't a patch release!

muratgozel commented 9 months ago

@maplesteve thanks, just implemented both of your suggestions, could you verify if its working? v3.0.21

maplesteve commented 8 months ago

@muratgozel Thanks - no errors with v3.0.21

muratgozel commented 8 months ago

@danielrhodes could you check too please?

muratgozel commented 8 months ago

closing this issue as all typings should work as expected as of version v3.0.23