-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Vite can't import from index.tsx after moving to nxViteTsPaths #19349
Comments
if it helps others - our current vite.config.ts file is this:
|
I'm experiencing the same issue for module subfolders with index files. |
After some research, I've found some causes with the
I did do the following things, and my project was built OK. // package: @nx/vite
// file: nx-tsconfig-paths.plugin.ts
resolveId(importPath: string) {
let resolvedFile: string;
try {
resolvedFile = matchTsPathEsm(
importPath,
undefined,
undefined,
options.extensions
);
} catch (e) {
logIt('Using fallback path matching.');
resolvedFile = matchTsPathFallback?.(
importPath,
undefined,
undefined,
options.extensions
);
}
if (!resolvedFile) {
if (tsConfigPathsEsm || tsConfigPathsFallback) {
logIt(
`Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`
);
resolvedFile =
loadFileFromPaths(tsConfigPathsEsm, importPath) ||
loadFileFromPaths(tsConfigPathsFallback, importPath);
} else {
logIt(`Unable to resolve ${importPath} with tsconfig paths`);
}
}
logIt(`Resolved ${importPath} to ${resolvedFile}`);
// Returning null defers to other resolveId functions and eventually the default resolution behavior
// https://rollupjs.org/plugin-development/#resolveid
return resolvedFile || null;
},
// package: tsconfig-paths
// file: try-path.ts
export function getStrippedPath(tryPath: TryPath): string {
return ["extension", "file", "index", "package"].indexOf(
tryPath.type
) !== -1
? tryPath.path
: exhaustiveTypeException(tryPath.type as never);
} STR file tree: - libs
- lib1
- src
- lib
- folder1
- index.ts
- index.ts STR tsconfig paths: "paths": {
"@/lib1": ["./libs/lib1/src/index.ts"],
"@/lib1/*": ["./libs/lib1/src/lib/*"]
} STR import string: import a from '@/lib1/folder1'; My Nx report: Node : 18.18.0 │Untracked files:
OS : darwin-x64 │ (use "git add <file>..." to include in what will be committed)
npm : 8.19.1 │ apps/studio/src/misc/isManager.ts
│
nx : 16.9.1 │no changes added to commit (use "git add" and/or "git commit -a")
@nx/js : 16.9.1 │➜ cnt-admin git:(develop) ✗ g add .
@nx/jest : 16.9.1 │➜ cnt-admin git:(develop) ✗ g status
@nx/linter : 16.9.1 │On branch develop
@nx/workspace : 16.9.1 │Changes to be committed:
@nx/cypress : 16.9.1 │ (use "git restore --staged <file>..." to unstage)
@nx/devkit : 16.9.1 │ new file: apps/studio/src/misc/isManager.ts
@nx/eslint-plugin : 16.9.1 │ modified: apps/studio/src/router.tsx
@nx/react : 16.9.1 │ modified: apps/studio/src/ui/App.tsx
@nrwl/tao : 16.9.1 │
@nx/vite : 0.0.1 │➜ cnt-admin git:(develop) ✗ g commit -am 'fix: disable intercom for
@nx/web : 16.9.1 │manage
typescript : 5.2.2 PS: @nx/vite@0.0.1 my local copy with suggested changes of @nx/vite@16.9.1 |
There exists the PR for this #19030 But, it solves the problem in a fallback section |
I have the same problem but without vite and nxViteTsPaths.
After full day of debugging (this is just my last try of removing extensions from index files, original is with index.ts paths), |
Hi eveybody, I've just found a new solution for this, explained everything in detail here: #21030 TL;DR: you can change the paths alias inside the |
For everybody here, I think the new version fixed that already. I added the same lines to In my case I needed to add: const resolvedIndexPath = (0, _nodepath.resolve)(path, `index${ext}`)
if ((0, _nodefs.existsSync)(resolvedIndexPath)) {
return resolvedIndexPath
} |
Closed as fixed: #21513 |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
after upgrading to nx 16 vite fails to resolve imports from other libs when using exports from index.tsx files.
this was fine prior to the nxViteTsPaths change.
this works:
while the new format - doesn't work
Expected Behavior
the new nxViteTsPaths() will work similar to viteTsConfigPaths and resolve imports correctly.
GitHub Repo
No response
Steps to Reproduce
prerequisites:
steps:
export { default as TestComponent } from "./Test"
with old viteconfig this works, with new one it doesn't
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
this seems somewhat related to #18492, but not quite
The text was updated successfully, but these errors were encountered: