Skip to content

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

Open
@ovsyannikov

Description

@ovsyannikov

{ 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 "css-modules-loader-core@1.1.0".
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 "postcss-modules@1.4.1" use function "FileSystemLoader" form "css-modules-loader-core@1.1.0".
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 "css-modules-loader-core@1.1.0".

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions