snowpack-plugin-hash
snowpack-plugin-hash copied to clipboard
Module import paths
After adding plugin, snowpack started generating backslashes ('\') instead of slashes ('/') in module paths. And now I have 'Failed to resolve module' error
👋 @EvgeniyLoginov sorry to hear you're having issues. Are you running on windows? Also, would you be able to help me with a small reproduction case?
@TylorS Yes, running on windows. I have pretty simple config:
module.exports = {
mount: {
public: {url: '/', static: true},
src: {url: '/dist'},
'node_modules/fontsource-roboto/files': '/files',
},
plugins: ['@snowpack/plugin-react-refresh', '@snowpack/plugin-dotenv', "snowpack-plugin-hash"],
routes: [
{"match": "routes", "src": ".*", "dest": "/index.html"},
],
};
After running 'build', for all import paths in all js files '/' is replaced with '\'
Thanks for the additional information. I'm not certain yet, but it'd be my guess that is some of the default behavior of node's path.join
or path.resolve
that is making this conversion. I'm pretty sure I haven't written any code that deliberately changes the paths. Do you happen to know of specific APIs I should look out for when trying to ensure compatibility on windows?
@TylorS Unfortunately no. I also suspect that some other library might be an issue, but since it happens after enabling plugin, I posted it here.
Roger that, I've opened a corresponding issue in the library that this plugin uses. I'll likely ping you to help me test it out since I don't have any windows machines to test on, if that's alright?
Sure, thanks for taking care of that
Hey @EvgeniyLoginov, sorry for the slow turnaround here. I've just gotten back from some vacation, so I'll try to make some time for this soon
@TylorS no problem. Issue doesn't appear when there is only 1 file, which is my case since I have bundling turned on. It'd still be good to have it fixed, but no rush from my side.
Do you happen to know of specific APIs I should look out for when trying to ensure compatibility on windows?
I assume you could just import 'path/posix'
instead of 'path'
, as 'path'
will automatically use 'path/win32'
on windows
edit:
It seems like you have do path.posix
, as const path = require('path/posix')
is not supported in my NodeJS version (14.16.0).
const path = require('path');
path.posix.resolve(...['Your', 'Path', 'to', 'resolve'])
A newer version of @typed/content-hash (v0.10.1) has been released an it utilizes require('path').posix
in an attempt to fix these issues