Skip to content
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

v4 fails on resolving common libraries outside root #87

Open
janakg opened this issue Dec 14, 2022 · 15 comments
Open

v4 fails on resolving common libraries outside root #87

janakg opened this issue Dec 14, 2022 · 15 comments
Labels
help wanted Extra attention is needed

Comments

@janakg
Copy link

janakg commented Dec 14, 2022

v3.6.0 works for a module outside the root, but v4 fails.

example:

tsconfigPathsPlugin({
  projects: [
    resolve('tsconfig.json'),
    resolve('../common-libs/color-lib/tsconfig.json'),
  ],
}) 
resolve: {
    alias: { '@sivi/color-lib': resolve(__dirname, '../common-libs/color-lib/src'),
}

tsconfig::

{
    "baseUrl": ".",
    "paths": {
      "*": ["./src/*"],
      "~/*": ["./*"],
      "@sivi/color-lib": ["../common-libs/color-lib/src/*"],
    }
}
@aleclarson
Copy link
Owner

Use DEBUG="vite-tsconfig-paths" vite dev and paste the logs here

@aleclarson aleclarson added the waiting for response The issue author needs to reply label Dec 14, 2022
@janakg
Copy link
Author

janakg commented Dec 14, 2022

Thanks! for quick response. 3.6.0 also has same logs but bundling works, in case of 4.0.3 bundling fails.

o/p of DEBUG="vite-tsconfig-paths" yarn vite dev

VITE v4.0.1  ready in 96 ms

 ➜  Local:   http://localhost:5173/
 ➜  Network: use --host to expose
 ➜  press h to show help
The following dependencies are imported but could not be resolved:

@sivi/color-lib (imported by /Users/janakg/cosmos/hub/templates/electron-app-main-template/src/renderer/app/index.tsx)
 resources/styles/globals.sass (imported by /Users/janakg/cosmos/hub/templates/electron-app-main-template/src/renderer/app/index.tsx)
 mathwasm (imported by /Users/janakg/cosmos/hub/templates/electron-app-main-template/src/renderer/app/index.tsx)
 @app/screens (imported by /Users/janakg/cosmos/hub/templates/electron-app-main-template/src/renderer/app/routes.tsx)

@aleclarson
Copy link
Owner

Seems like vite-tsconfig-paths isn't being used (or DEBUG isn't being applied correctly), as none of its logs are visible there. Could you try running DEBUG="vite-tsconfig-paths" node_modules/.bin/vite dev instead?

@janakg
Copy link
Author

janakg commented Dec 15, 2022

@aleclarson it is used for sure, else I am getting error

import tsconfigPathsPlugin from 'vite-tsconfig-paths'
const tsconfigPaths = tsconfigPathsPlugin({
  projects: [
    resolve('tsconfig.json'),
    resolve('../common-libs/color-lib/tsconfig.json'),
  ],
})
defineConfig({
    plugins: [tsconfigPaths]
}

Debug is not working for both commands
I am using it inside electron-vite config , which inturn uses vite

I'll send you a test repo, if that helps

@aleclarson
Copy link
Owner

That would help

@Ludea
Copy link

Ludea commented Dec 16, 2022

get same issue:
Running tsconfig-paths in DEBUG mode gives:

[4/4] Building fresh packages...
Done in 27.32s.
2022-12-16T06:31:21.127Z vite-tsconfig-paths options.root   == undefined
2022-12-16T06:31:21.128Z vite-tsconfig-paths project root   == /home/runner/work/tauri-mobile/tauri-mobile
2022-12-16T06:31:21.128Z vite-tsconfig-paths workspace root == /home/runner/work/tauri-mobile/tauri-mobile
2022-12-16T06:31:21.240Z vite-tsconfig-paths projects: [
  '/home/runner/work/tauri-mobile/tauri-mobile/tauri/examples/web/tsconfig.json',
  '/home/runner/work/tauri-mobile/tauri-mobile/tauri/tooling/api/tsconfig.json',
  '/home/runner/work/tauri-mobile/tauri-mobile/tauri/tooling/cli/templates/plugin/with-api/examples/svelte-app/tsconfig.json',
  '/home/runner/work/tauri-mobile/tauri-mobile/tauri/tooling/cli/templates/plugin/with-api/webview-src/tsconfig.json',
  '/home/runner/work/tauri-mobile/tauri-mobile/tsconfig.json'
]
error when starting dev server:
TSConfckParseError: failed to resolve "extends":"@tsconfig/svelte/tsconfig.json" in /home/runner/work/tauri-mobile/tauri-mobile/tauri/tooling/cli/templates/plugin/with-api/examples/svelte-app/tsconfig.json
    at resolveExtends (file:///home/runner/work/tauri-mobile/tauri-mobile/node_modules/tsconfck/dist/index.js:459:9)
    at parseExtends (file:///home/runner/work/tauri-mobile/tauri-mobile/node_modules/tsconfck/dist/index.js:432:34)
    at Module.parse (file:///home/runner/work/tauri-mobile/tauri-mobile/node_modules/tsconfck/dist/index.js:383:24)
    at async Promise.all (index 2)
    at async configResolved (file:///home/runner/work/tauri-mobile/tauri-mobile/node_modules/vite-tsconfig-paths/dist/index.mjs:94:9)
    at async Promise.all (index 1)
    at async resolveConfig (file:///home/runner/work/tauri-mobile/tauri-mobile/node_modules/vite/dist/node/chunks/dep-2285ba4f.js:62801:5)
    at async createServer (file:///home/runner/work/tauri-mobile/tauri-mobile/node_modules/vite/dist/node/chunks/dep-2285ba4f.js:61878:20)
    at async CAC.<anonymous> (file:///home/runner/work/tauri-mobile/tauri-mobile/node_modules/vite/dist/node/cli.js:729:24)
Error: Process completed with exit code 1.

@aleclarson
Copy link
Owner

@Ludea That seems to be a different issue (not a similar error message).

@Ludea
Copy link

Ludea commented Dec 16, 2022

Should I open a new issue to track this ?

@aleclarson
Copy link
Owner

@Ludea First, check that @tsconfig/svelte exists in node_modules. If it does, I'd recommend opening an in issue in tsconfck about it.

@Ludea
Copy link

Ludea commented Dec 16, 2022

The folder doesn't exists into node_modules

@aleclarson
Copy link
Owner

Then it's not an issue with this plugin or tsconfck.

@janakg
Copy link
Author

janakg commented Dec 24, 2022

@aleclarson sorry for the delay.

please find the rep : https://github.com/janakg/tsconfig-path-lib-path-issue

Just switch between version 3.6.0 and 4.0.3 of vite-tsconfig-paths , currently it works only in 3.6.0. Also, i don't know how to get the debug log working in this setup

As I have mentioned before this is via electron-vite (it is a thin wrapper library on vite for ease of use for electron apps)

@aleclarson aleclarson added help wanted Extra attention is needed and removed waiting for response The issue author needs to reply labels Dec 27, 2022
@aleclarson
Copy link
Owner

aleclarson commented Dec 27, 2022

Thanks for the reproduction. No estimates on when I'll be able to take a look though. Hopefully someone else will step in and investigate!

@janakg
Copy link
Author

janakg commented Dec 29, 2022

sure, thanks for the update. we will stick to 3.6.0 for now.

@ylc395
Copy link

ylc395 commented May 4, 2024

I believe that this bug is introduced by this commit:

2361b2e

Since this commit, this plugin doesn't resolve any import path when the importer is not a descanter of the tsconfig file specified by project field.

How can we fix this? I can contribute a PR about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants