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

Double "C:\\C:\\" in the file paths #232

Open
ovsyannikov opened this issue Jun 20, 2019 · 0 comments
Open

Double "C:\\C:\\" in the file paths #232

ovsyannikov opened this issue Jun 20, 2019 · 0 comments

Comments

@ovsyannikov
Copy link

ovsyannikov commented Jun 20, 2019

{ Error: ENOENT: no such file or directory, open 'C:\C:\project\src\components\style.css'
at Error (antive)
error: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\C:\project\src\components\style.css'
}

I use "[email protected]".
The problem in file "node_modules/css-modules-loader-core/lib/file-system-loader.js" in the row number 64:

fileRelativePath = _path2['default'].resolve(_path2['default'].join(_this.root, relativeDir), newPath);

If "_this.root" equals to "/" and "relativeDir" equals to "C:\project\src\components\MyReactComponent" in function "_path2['default'].join(_this.root, relativeDir)" then result will be:

\C:\project\src\components\MyReactComponent

After that, if "newPath" equals to "../style.css", then in the function "_path2['default'].resolve('\C:\project\src\components\MyReactComponent', './style.css')" result will be:

C:\C:\project\src\components\style.css

And this is the error.

The problem is in the "_this.root", that is equal to "/".

"/" comes from the "root" - the argument of function "FileSystemLoader":

function FileSystemLoader(root, plugins) {
this.root = root;
...
...
var _this = this;
...
...
fileRelativePath = _path2['default'].resolve(_path2['default'].join(_this.root, relativeDir), newPath);

Package "[email protected]" use function "FileSystemLoader" form "[email protected]".
In this package in the file "node_module/postcss-modules/build/index.js" in rows 54-57 exists this code:

function getLoader(opts, plugins) {
const root = typeof opts.root === "undefined" ? "/" : opts.root;
return typeof opts.Loader === "function" ? new opts.Loader(root, plugins) : new _fileSystemLoader2.default(root, plugins);
}

In this code if "typeof opts.root === "undefined"" then "root" equalt to "/".
After that "/" goes to "new _fileSystemLoader2.default(root, plugins);".

_fileSystemLoader2 is imported "FileSystemLoader" form "[email protected]".

I propose to replace in file "node_modules/css-modules-loader-core/lib/file-system-loader.js" this row number 64:

fileRelativePath = _path2['default'].resolve(_path2['default'].join(_this.root, relativeDir), newPath);

to this code:

var fileRelativePath;
if (_this.root === '/') {
fileRelativePath = _path2['default'].resolve(relativeDir, newPath);
} else {
fileRelativePath = _path2['default'].resolve(_path2['default'].join(_this.root, relativeDir), newPath);
}

Perhaps this will fix the bug.

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

1 participant