Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webpack-scripts] are broken on Windows due to postcss-normalize #70

Open
ThaNarie opened this issue Jul 11, 2022 · 0 comments
Open

[webpack-scripts] are broken on Windows due to postcss-normalize #70

ThaNarie opened this issue Jul 11, 2022 · 0 comments

Comments

@ThaNarie
Copy link
Member

This PR csstools/postcss-normalize#65 fixes an issue with postcss-normalize that breaks webpack dev/build on Windows currently.

That package is using broken and unsupported internal node functions to resolve folders on Windows.

I tested the patch, and that's working fine:

diff --git a/node_modules/postcss-normalize/index.mjs b/node_modules/postcss-normalize/index.mjs
index 03594d3..7c2f333 100644
--- a/node_modules/postcss-normalize/index.mjs
+++ b/node_modules/postcss-normalize/index.mjs
@@ -1,5 +1,5 @@
 import postcssBrowserComments from 'postcss-browser-comments';
-import Module from 'module';
+import { createRequire} from 'node:module'
 import path from 'path';
 import { URL } from 'url';
 import fs from 'fs';
@@ -8,9 +8,8 @@ import postcss from 'postcss';
 const assign = (...objects) => Object.assign(...objects);
 const create = (...objects) => assign(Object.create(null), ...objects);
 
-const currentURL = import.meta.url;
-const currentFilename = new URL(currentURL).pathname;
-const currentDirname = path.dirname(currentFilename); // get resolved filenames for normalize.css
+// create package path resolver in an esm-compatible fashion
+const {resolve: requireResolve} = createRequire(import.meta.url) 
 
 const normalizeCSS = resolve('@csstools/normalize.css');
 const normalizeDir = path.dirname(normalizeCSS);
@@ -54,11 +53,7 @@ const resolvedFilenamesById = create({
 }); // get the resolved filename of a package/module
 
 function resolve(id) {
-  return resolve[id] = resolve[id] || Module._resolveFilename(id, {
-    id: currentFilename,
-    filename: currentFilename,
-    paths: Module._nodeModulePaths(currentDirname)
-  });
+  return resolve[id] = resolve[id] || requireResolve(id)
 }
 
 const cache$1 = create();

If you place the above file as postcss-normalize+10.0.1.patch in the project's patches folder, and run npx patch-package, it will apply the fix for you.


I'd would like to have created a PR for this, but i'm not sure how this would work for script packages. As currently patches only exist in templates, and some templates are compatible with multiple script packages, there is no obvious place to do this.

Maybe we should create a new ticket to add support for scripts-patches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants