Type error when using a baseURL and paths in a next project
I get this error when I go to build or type check with TSC on my NextJS 12 Project.
node_modules/iron-session/next/index.ts:8:48 - error TS2307: Cannot find module '../src/getPropertyDescriptorForReqSession' or its corresponding type declarations.
8 import getPropertyDescriptorForReqSession from "../src/getPropertyDescriptorForReqSession";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
in my tsconfig.json it looks like
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["*"]
},
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"jsxImportSource": "@emotion/react",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
If I remove these bits
"baseUrl": ".",
"paths": {
"@/*": ["*"]
},
Works just fine but I'd really love to be able to use alias'.
Is this something that can be changed on a package side or is it just a configuration problem on my side?
Any chance this can be merged? It's also happening to us
Hey I am confused because I also use baseUrl: "." in my projects so I am wondering what's really wrong here? If someone can reduce the necessary changes too that would be great. The current PR for this (thanks @csprance) includes multiple things I don't get why the library should be doing.
Importing a file with a relative path in the library shouldn't trigger an issue on the consumer side. Please provide some more information/dig more if possible with reference links to issue on TS/Next. Thanks!
I had the same problem and could solve it by changing the import path. Before I imported modules from iron-session/next which resulted in the error described by @csprance. Changing the path to iron-session/next/dist fixed it.
I'm not sure why it happens I just know this fixes it. I was using a bunch of different libs and this was the only one that had issues with baseURL.
In the end I just ended up duplicating the lib in my own codebase to deal with the changes.
Hey there, you can see that our official TypeScript example is also using baseUrl as seen here: https://github.com/vvo/iron-session/blob/f9d0351e11c2553ad605f17cf1c139b79eee1db1/examples/next.js-typescript/tsconfig.json#L20 and we then import this way: https://github.com/vvo/iron-session/blob/f9d0351e11c2553ad605f17cf1c139b79eee1db1/examples/next.js-typescript/pages/api/login.ts#L4 which has no problem.
So most probably there's something different in your setup and you'll need to find what's the difference. Thanks!
I don't think the issue is with the baseURL it's with the path section.
Same issue here. Had to import it from /dist as well as mentioned here: https://github.com/vvo/iron-session/issues/455#issuecomment-1100040845
For context, this is an issue with Jest which isn't able to resolve ESM that well.
It looks like the package has an import that's depending on something in the src folder, which I'm guessing is removed from the deployed package (and replaced with dist).