You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have three packages in my monorepo - all of them are publishable:
@my-org/types residing in packages/types
tsc used as a bundler
@my-org/sdk residing in packages/sdk/core
tsc used as a bundler
@my-org/sdk-react residing in packages/sdk/react
tried using both rollup and vite as bundlers but both giving me incorrect import paths in the built files
The dependencies are as follows:
sdk is dependent on types
sdk-react is dependent on types and sdk
Within the source code, all the imports look alright. I am importing types and other elements from other packages using their respective import paths.
The problem is when I build them. In the dist folder of the React package the imports seem off, instead of still referencing the import path, depending on the bundler, I am either getting relative or absolute imports referencing the codebase. This is problematic as it results in incorrect types imports in the projects which use all those packages.
Example:
using rollup - one of the d.ts files from the bundled React project:
Here an interesting thing is that things from the types package are imported correctly. In some other bundled files even the sdk files seem to have correct imports, though even then when browsing through the dist folder inside the NX repo, there's a TS error of Cannot find module or its corresponding type declarations. - there's no such error with the imports from the types package.
using vite - one of the d.ts files from the bundled React project:
An observation I have made is that this problem appears in files which do not have a DIRECT import from that library to which the path is not correct.
If I import anything whatsoever from @my-org/sdk in the source file (the file which resulting d.ts file is problematic), even if i don't use that import for anything, the result is correct. Otherwise the import paths are incorrect and refer to the local placement of the files, not to the import path. This is for sure not intuitive though and I don't think it should work that way?
Expected Behavior
I would expect the bundled file to have correct import paths, something like, no matter the direct or indirect import of those classes/types:
Current Behavior
I have three packages in my monorepo - all of them are publishable:
@my-org/types
residing inpackages/types
tsc
used as a bundler@my-org/sdk
residing inpackages/sdk/core
tsc
used as a bundler@my-org/sdk-react
residing inpackages/sdk/react
rollup
andvite
as bundlers but both giving me incorrect import paths in the built filesThe dependencies are as follows:
sdk
is dependent ontypes
sdk-react
is dependent ontypes
andsdk
Within the source code, all the imports look alright. I am importing types and other elements from other packages using their respective import paths.
The problem is when I build them. In the dist folder of the React package the imports seem off, instead of still referencing the import path, depending on the bundler, I am either getting relative or absolute imports referencing the codebase. This is problematic as it results in incorrect types imports in the projects which use all those packages.
Example:
using rollup - one of the
d.ts
files from the bundled React project:Here an interesting thing is that things from the
types
package are imported correctly. In some other bundled files even thesdk
files seem to have correct imports, though even then when browsing through thedist
folder inside the NX repo, there's a TS error ofCannot find module or its corresponding type declarations.
- there's no such error with the imports from thetypes
package.using vite - one of the
d.ts
files from the bundled React project:An observation I have made is that this problem appears in files which do not have a DIRECT import from that library to which the path is not correct.
If I import anything whatsoever from
@my-org/sdk
in the source file (the file which resultingd.ts
file is problematic), even if i don't use that import for anything, the result is correct. Otherwise the import paths are incorrect and refer to the local placement of the files, not to the import path. This is for sure not intuitive though and I don't think it should work that way?Expected Behavior
I would expect the bundled file to have correct import paths, something like, no matter the direct or indirect import of those classes/types:
GitHub Repo
https://github.com/pawicao/nx-imports-playground
Steps to Reproduce
Reproducing:
npm install
nx run-many -t build
dist/packages/sdk/react/sdk-react.d.ts
for an example"Fixing":
packages/sdk/react/src/lib/sdk-react.tsx
change the import from:d.ts
file will be correctNx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: