snowpack-plugin-hash icon indicating copy to clipboard operation
snowpack-plugin-hash copied to clipboard

Module import paths

Open EvgeniyLoginov opened this issue 3 years ago • 10 comments

After adding plugin, snowpack started generating backslashes ('\') instead of slashes ('/') in module paths. And now I have 'Failed to resolve module' error

EvgeniyLoginov avatar May 31 '21 08:05 EvgeniyLoginov

👋 @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 avatar Jun 01 '21 14:06 TylorS

@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 '\'

EvgeniyLoginov avatar Jun 01 '21 15:06 EvgeniyLoginov

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 avatar Jun 01 '21 16:06 TylorS

@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.

EvgeniyLoginov avatar Jun 02 '21 14:06 EvgeniyLoginov

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?

TylorS avatar Jun 02 '21 14:06 TylorS

Sure, thanks for taking care of that

EvgeniyLoginov avatar Jun 02 '21 15:06 EvgeniyLoginov

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 avatar Jun 24 '21 19:06 TylorS

@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.

EvgeniyLoginov avatar Jun 28 '21 17:06 EvgeniyLoginov

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'])

N0tExisting avatar Jul 05 '21 16:07 N0tExisting

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

TylorS avatar May 19 '22 20:05 TylorS