[Bug] Absolute paths leaking in the bundle
See original GitHub issueReporting a bug?
Absolute paths are found in the exported bundles. This is surprising, can leak information about your build system, and will cause webpack longterm caching to not work if you build your site in different directories over time (or on multiple servers).
I believe the caching is two fold, part of it would be to use contenthash
and second would be to use relative path for referencing modules.
I know there’s been a lot of work put into using absolute paths over relative paths lately, and I wonder if we could achieve the same result with relative paths instead (unclear what the issue was) ?
Environment
envinfo result
❯ npx envinfo --system --npmPackages 'react*' --binaries --npmGlobalPackages 'react*' --browsers
npx: installed 1 in 1.434s
System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
Memory: 6.09 GB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 8.14.0 - ~/n/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Browsers:
Chrome: 76.0.3809.132
Firefox: 69.0
Safari: 12.1.1
npmPackages:
react: ^16.9.0 => 16.9.0
react-dom: ^16.9.0 => 16.9.0
react-static: ^7.2.0 => 7.2.2
react-static-plugin-reach-router: ^7.2.0 => 7.2.2
react-static-plugin-sitemap: ^7.2.0 => 7.2.2
react-static-plugin-source-filesystem: ^7.2.0 => 7.2.2
Steps to Reproduce the problem
- Install a “basic” react-static site
❯ react-static create
? What should we name this project? my-static-site
? Select a template below... basic
Creating new react-static project...
cd my-static-site
yarn build
- Look in the
dist/main.*.js
file and find absolute paths. If you’re on Mac, this mean you’d find/Users/[your-user]/...
paths in there.
Another way to see these absolute path is to run yarn serve
and look at the sources
tab in the devtools. You should see absolute path there:
Expected Behavior
I would expect not to find absolute paths in the bundles.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:20 (5 by maintainers)
I’ve played around with node to remove the root paths from the
js
,json
andhtml
indist/
directory and it finally works.Beware hardcoded paths in my snippet – it works for my setup (Unix, MacOS and default /dist & /src paths). UPDATED: there has been some bugs on Linux builds, so I added several fixes to handle empty dirs after file moving operations. So, here is my plugin which runs after bundling and exporting during
build
:Thanks, but nothing is perfect, you know 😉 Check my code update, hope that will help better)