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

Bug:Cannot load resources that start with //. #15335

Closed
7 tasks done
zhe-he opened this issue Dec 13, 2023 · 7 comments · Fixed by #15355
Closed
7 tasks done

Bug:Cannot load resources that start with //. #15335

zhe-he opened this issue Dec 13, 2023 · 7 comments · Fixed by #15355

Comments

@zhe-he
Copy link

zhe-he commented Dec 13, 2023

Describe the bug

Adding font resources that start with // in the index.html file in the root directory causes an error in the console. The error message is [vite] Pre-transform error: Failed to load url //at.alicdn.com/t/c/font_3604131_25pwmwrknp2.js (resolved id: //at.alicdn.com/t/c/font_3604131_25pwmwrknp2.js). Does the file exist?

Reproduction

vite@5.0.8

Steps to reproduce

  1. Create an empty project with Vite.
  2. Add <script src="//at.alicdn.com/t/c/font_3604131_25pwmwrknp2.js"></script> in the index.html file in the root directory.
  3. Run npm run dev to start the development server.
  4. Make changes and save them locally to trigger hot-reloading.
  5. Encounter an error : [vite] Pre-transform error: Failed to load url //at.alicdn.com/t/c/font_3604131_25pwmwrknp2.js (resolved id: //at.alicdn.com/t/c/font_3604131_25pwmwrknp2.js). Does the file exist?
image

System Info

System:
    OS: macOS 12.4
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
    Memory: 109.20 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 20.10.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.6.11 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 120.0.6099.71
    Safari: 15.5

Used Package Manager

npm

Logs

No response

Validations

@XiSenao
Copy link
Collaborator

XiSenao commented Dec 14, 2023

It seems that Vite does not currently support paths starting with //. You can try to complete the path so that Vite recognizes it as an external path.

@zhe-he
Copy link
Author

zhe-he commented Dec 15, 2023

In versions prior to vite@5.0.8, this error did not exist. It only appeared after I upgraded to 5.0.8. I cannot forcibly add the prefix 'https' or 'http' because this project will run in different environments, so it must be relative. Therefore, I hope vite can either ignore this type of relative error or not prompt this error as it did before.

@XiSenao
Copy link
Collaborator

XiSenao commented Dec 15, 2023

Thank you for the reminder, this could be a problem.

@anewstead
Copy link

anewstead commented Dec 15, 2023

noticed same error in terminal also on particular ./ import

error introduced vite@5.0.8 and still there in vite@5.0.9

[vite] Pre-transform error: Failed to load url /sb-preview/runtime.js (resolved id: /sb-preview/runtime.js). Does the file exist?

This from Storybook generated HTML, which references file twice:

<link href="./sb-preview/runtime.js" rel="prefetch" as="script">
<script type="module" src="./sb-preview/runtime.js"></script>

the file is actually served, can navigate to it, and the page runs with no error in browser,
running npm storybook dev on localhost,

maybe the rel="prefetch" ?
or some runtime race condition.

there are many other ./ files in the HTML that do not error, such as:
<link href="./sb-manager/runtime.js" rel="modulepreload">
<script type="module"> import './sb-manager/runtime.js'; ... </script>

@XiSenao
Copy link
Collaborator

XiSenao commented Dec 15, 2023

noticed same error in terminal also on particular ./ import

error introduced vite@5.0.8 and still there in vite@5.0.9

[vite] Pre-transform error: Failed to load url /sb-preview/runtime.js (resolved id: /sb-preview/runtime.js). Does the file exist?

This from Storybook generated HTML, which references file twice:

<link href="./sb-preview/runtime.js" rel="prefetch" as="script"> <script type="module" src="./sb-preview/runtime.js"></script>

the file is actually served, can navigate to it, and the page runs with no error in browser, running npm storybook dev on localhost,

maybe the rel="prefetch" ? or some runtime race condition.

there are many other ./ files in the HTML that do not error, such as: <link href="./sb-manager/runtime.js" rel="modulepreload"> <script type="module"> import './sb-manager/runtime.js'; ... </script>

Sorry, I can't reproduce the issue you provided. Could you please provide a minimal reproduction repository?

@anewstead
Copy link

anewstead commented Dec 15, 2023

Sorry, I can't reproduce the issue you provided. Could you please provide a minimal reproduction repository?

error happens from clean install.

mac,
node@20.10.0 (nvm),
pnpm@8.12.1

pnpm create vite > react > typescript
pnpm dlx storybook@latest init > eslint

to confirm deps this gave me ...

"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.6.5",
"@storybook/addon-interactions": "^7.6.5",
"@storybook/addon-links": "^7.6.5",
"@storybook/addon-onboarding": "^1.0.10",
"@storybook/blocks": "^7.6.5",
"@storybook/react": "^7.6.5",
"@storybook/react-vite": "^7.6.5",
"@storybook/test": "^7.6.5",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"eslint-plugin-storybook": "^0.6.15",
"storybook": "^7.6.5",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}

run dev server:
pnpm storybook

@XiSenao
Copy link
Collaborator

XiSenao commented Dec 18, 2023

The issue you described is related to #15374. @anewstead

@github-actions github-actions bot locked and limited conversation to collaborators Jan 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants