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

Path includes a dot (.) character #4556

Closed
7 tasks done
maratnasyrov opened this issue Aug 9, 2021 · 6 comments · Fixed by vanilla-extract-css/vanilla-extract#290 or #4708
Closed
7 tasks done

Path includes a dot (.) character #4556

maratnasyrov opened this issue Aug 9, 2021 · 6 comments · Fixed by vanilla-extract-css/vanilla-extract#290 or #4708
Labels
bug: upstream Bug in a dependency of Vite

Comments

@maratnasyrov
Copy link

maratnasyrov commented Aug 9, 2021

Describe the bug

When trying to load styles from a file from another library using @vanilla-extract/vite-plugin, an error occurs on the dev server:
vite:spa-fallback Not rewriting GET /@id/ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?hash=0b6a2903c4458e87f00567205ad0a3b6 because the path includes a dot (.) character.

This only occurs if you install the library from the local repository.

At first I thought that the problem might be in the plugin itself, but after debugging I realized that the following path is passed to the @vanilla-extract/vite-plugin for exporting styles:
These two points cause this error
MainApp/../ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?source=LnN0eWxlc19fN3ltc2N6MCB7CiAgY29sb3I6ICNmZjAwMDA7CiAgZm9udC1zaXplOiAyMHB4Owp9

Reproduction

git clone [email protected]:maratnasyrov/ComponentsApp.git
git clone [email protected]:maratnasyrov/MainApp.git
cd MainApp
npm install -S ../ComponentsApp
npm run dev
Open localhost:3000 in browser

Also, this error can be seen in the console

System Info

System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i3-4170 CPU @ 3.70GHz
    Memory: 413.61 MB / 15.58 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
    Yarn: 1.17.3 - /usr/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.3/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 92.0.4515.107
    Firefox: 90.0.2

Used Package Manager

npm

Logs

vite:load 0ms   [fs] ../ComponentsApp/src/components/Button/styles.css.ts +43ms
  vite:resolve 1ms   MainApp/../ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?source=LnN0eWxlc19fMXVoNTl2MjAgewogIGNvbG9yOiAjZmYwMDAwOwogIGZvbnQtc2l6ZTogMjBweDsKfQ== -> MainApp/../ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?hash=6785b7839a3057ae265165081227272a +62ms
  vite:resolve 1ms   /@id/ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?hash=6785b7839a3057ae265165081227272a -> null +1ms
  vite:transform 43ms  ../ComponentsApp/src/components/Button/styles.css.ts +60ms
  vite:time 45ms  ../ComponentsApp/src/components/Button/styles.css.ts +59ms
  vite:resolve 1ms   ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?hash=6785b7839a3057ae265165081227272a -> null +12ms
  vite:spa-fallback Not rewriting GET /@id/ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?hash=6785b7839a3057ae265165081227272a because the path includes a dot (.) character. +838ms
  vite:time 3ms   /@id/ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?hash=6785b7839a3057ae265165081227272a +13ms

Validations

@Kashuab
Copy link

Kashuab commented Aug 9, 2021

+1

In my case, I need to parse a JWT from the URL which is part of the path. For example:

http://localhost:4000/some-path/ag348g9ha3e48rhgalsdkf.f23agw4eg89asdhg.Ddufasfmwi9o0efjnE

In the meantime, I'll try to convince my colleagues to use a query string instead 😄

@ygj6
Copy link
Member

ygj6 commented Aug 10, 2021

Duplicate of #4344

@ygj6 ygj6 marked this as a duplicate of #4344 Aug 10, 2021
@ygj6 ygj6 added duplicate This issue or pull request already exists and removed pending triage labels Aug 10, 2021
@ygj6 ygj6 marked this as not a duplicate of #4344 Aug 12, 2021
@ygj6 ygj6 added bug and removed duplicate This issue or pull request already exists labels Aug 12, 2021
ygj6 added a commit to ygj6/vanilla-extract that referenced this issue Aug 13, 2021
@ygj6 ygj6 added bug: upstream Bug in a dependency of Vite and removed bug labels Aug 13, 2021
@ygj6
Copy link
Member

ygj6 commented Aug 14, 2021

First, I apologize that I mistakenly marked it as a duplicate at the beginning.

I tested this issue and only the npm installed dependencies have this problem, the yarn installed dependencies do not have this problem.

Because vite resolves the locally installed ComponentsApp dependencies to different paths:

export function resolvePackageData(
id: string,
basedir: string
): PackageData | undefined {
const cacheKey = id + basedir
if (packageCache.has(cacheKey)) {
return packageCache.get(cacheKey)
}
try {
const pkgPath = resolveFrom(`${id}/package.json`, basedir)
return loadPackageData(pkgPath, cacheKey)
} catch (e) {
isDebug && debug(`${chalk.red(`[failed loading package.json]`)} ${id}`)
}
}

local dependency for the yarn installation, obtained by resolve, is a link address:
root/MainApp/node_modules/ComponentsApp/src/index.ts

and the local dependencies installed by npm get a real address:
root/ComponentsApp/src/index.ts

this causes the transform hook that triggers @vanilla-extract/vite-plugin to parse @vanilla-extract/css as:
MainApp/../ComponentsApp/src/components/Button/styles.css.ts.vanilla.css?source=LnN0eWxlc19fMXVoNTl2MjAgewogIGNvbG9yOiAjZmYwMDAwOwogIGZvbnQtc2l6ZTogMjBweDsKfQ==

later, when entering the resolveId hook of @vanilla-extract/vite-plugin, the path above is used as the key to store static CSS code, but Vite normalizes this path before the end of the resolveId hook as follows:

if (id) {
partial.id = isExternalUrl(id) ? id : normalizePath(id)
return partial as PartialResolvedId
} else {

the path becomes:
root/ComponentsApp/src/components/Button/styles.css.ts

this leads to later loading the style with the load hook, using the normalized path as the key to get the static CSS code, which is inconsistent with the code used when storing, so it cannot be found and eventually leads to a 404.

I will submit a pr in the @vanilla-extract/vite-plugin community to fix this issue. This issue I marked as upstream because I think normalization can avoid a lot of security issues, so we should normalize the path.

@maratnasyrov
Copy link
Author

@ygj6 thanks for your quick response and analysis of this problem. I have not tried using yarn in this case yet, but I think it might be a temporary solution until your changes in vanila-extract are published.

ygj6 added a commit to ygj6/vanilla-extract that referenced this issue Aug 17, 2021
mattcompiles pushed a commit to vanilla-extract-css/vanilla-extract that referenced this issue Aug 17, 2021
@ygj6
Copy link
Member

ygj6 commented Aug 17, 2021

@ygj6 thanks for your quick response and analysis of this problem. I have not tried using yarn in this case yet, but I think it might be a temporary solution until your changes in vanila-extract are published.

PR has been merged and @vanilla-extract/vite-plugin has released 1.1.2 version, I tested it and the issue has been solved, you can try it.
https://github.com/seek-oss/vanilla-extract/releases/tag/%40vanilla-extract%2Fvite-plugin%401.1.2

@mseele
Copy link

mseele commented Aug 25, 2021

Checkout vite plugin https://github.com/ivesia/vite-plugin-rewrite-all
This should fix the problem (see also #2190)

@github-actions github-actions bot locked and limited conversation to collaborators Sep 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite
Projects
None yet
4 participants