next-runtime
next-runtime copied to clipboard
Dereference Public Symlinks
Our next.js site has some symlinks in the public/ directory to files outside the public directory. (These files come from a git submodule which is why they aren't in the public directory directly.) The file layout looks like
next-config.js
package.json
pages/...
thesubrepo/screenshots/aaa.png
thesubrepo/screenshots/bbb.png
public/somedirectfile
public/screenshots (screenshots is a symlink to "../thesubrepo/screenshots")
The pages then reference /screenshots/aaa.png which works great during development. The issue is during deployment the copyPublicFiles function https://github.com/netlify/netlify-plugin-nextjs/blob/main/src/lib/steps/copyPublicFiles.js does not dereference the symlink so what happens is that in the netlify publish path there is a symlink screenshots to a directory that does not exist.
The copySync function https://github.com/jprichardson/node-fs-extra/blob/HEAD/docs/copy-sync.md has an option dereference but it defaults false.
Maybe it would be a backwards compatibility problem to just always set dereference to true, but could there be an option or config setting somewhere to enable dereferencing public files when copying them to the publish directory? Maybe an environment variable? Just need to pass dereference: true to copySync.
For now, I have worked around this by manually copying the files as an additional build step.
@wuzzeb whoa very interesting! thanks for opening this with us :) glad you have a temporary workaround. i think it's likely we can safely default dereference to true instead, and if not, it's definitely reasonable to make this configurable. we'll keep you updated!!
Hello! We don't suggest symlinking files outside of the site itself. Your workaround for copying the files in the build command is the right way to achieve what you're looking for. 😄
If you run into any bugs during the build step, let us know!