Markdown links linking to JS files should resolve to the asset url, not transpiled code
Have you read the Contributing Guidelines on issues?
- [x] I have read the Contributing Guidelines on issues.
Prerequisites
- [x] I'm using the latest version of Docusaurus.
- [x] I have tried the
npm run clearoryarn clearcommand. - [x] I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - [ ] I have tried creating a repro with https://new.docusaurus.io.
- [x] I have read the console error message carefully (if applicable).
Description
Something similar to https://github.com/facebook/docusaurus/issues/10460
Reproducible demo
No response
Steps to reproduce
This is simple to reproduce.
- Create a fresh docusaurus site.
- Create a file
static/assets/upload/test.js:
{
- / -sss;
}
- Create a link in the documentation to this file
---
sidebar_position: 6
---
# Congratulations!
[Test](/assets/upload/test.js)
This will break a build (rspack also). It looks like https://github.com/facebook/docusaurus/issues/10460.
If the ‘invalid’ JavaScript is in the folder, but there is no reference to it, everything will build correctly.
Expected behavior
Documentation is built even if there is a reference to an invalid JavaScript file in static assets.
Actual behavior
[ERROR] Client bundle compiled with errors therefore further build is impossible.
SyntaxError: /temp/docusaurus-rs-pack/my-website/static/assets/upload/test.js: Unterminated regular expression. (2:5)
1 | {
> 2 | - / -sss;
| ^
3 | }
4 |
at parser.next (<anonymous>)
at normalizeFile.next (<anonymous>)
at run.next (<anonymous>)
at transform.next (<anonymous>)
Your environment
docusaurus 3.7.0 node 20.17.0 npm 10.8.2
Self-service
- [ ] I'd be willing to fix this bug myself.
Hi, this is working as expected. The static folder doesn't mean "no bundling"; it just means it will be copied to the output folder. You can use pathname:// to opt out. See https://docusaurus.io/docs/markdown-features/assets#static-assets
@Josh-Cena Thank you for pointing this out to me! I didn't notice that. Great!
Hi, this is working as expected.
Hmm, I'm not so sure in this case.
Markdown links referencing files are converted to require() calls, and by default require("./some.js") returns the transpiled module.
When it's used inside a Markdown links, returning the transpiled module has no utility at all IMHO, and we should probably use webpack file-loader in this case.
pathname:// is a decent workaround, but I still think we could improve a bit the default behavior for this edge case.
Note: this is unrelated to https://github.com/facebook/docusaurus/issues/10460
So your opinion is that it should still go through the bundler and get hashed, just should use file-loader instead of js-loader? That makes sense to me.