ClojureScript

A folders index.js does not provide the parent dir as module

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.10.238
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

In Javascript when a module is required you can omit the extension in the relative path form. If you do and the path is a directory and that directory contains an `index.js`, that file is treated as the main script.

So, this statement:

```javascript
const foo = require('./foo')
```

Can be resolved as `./foo.js` or `./foo/index.js`.

The module resolver should take this into account, and if an `index.js` is resolved in a required directory, it should also provide like both

```
module$Users$user$Documents$project$node_modules$foo$index
module$Users$user$Documents$project$node_modules$foo
```

Actual repr here: [cljs-name-to-path-issue](https://github.com/rangeoshun/cljs-name-to-path-issue)

It produced the following error in browser:

`Undefined nameToPath for module$Users$range$Documents$cljs_name_to_path_issue$node_modules$deat_mui_core$colors`

It is because `node_modules/deat-mui-core/colors/index.js` only provides the following in the compiled version:

```javascript
goog.provide("module$Users$range$Documents$cljs_name_to_path_issue$node_modules$deat_mui_core$colors$index");
```

It should also provide if that makes no confilct:

```javascript
goog.provide("module$Users$range$Documents$cljs_name_to_path_issue$node_modules$deat_mui_core$colors");
```

Activity

Hide
Abel Varga added a comment -

Sorry for faulty markdown

Show
Abel Varga added a comment - Sorry for faulty markdown
Hide
Abel Varga added a comment -

Please close, as looking through the tests it seems it works, so the `lein-cljsbuild` might be out of date on this dep.

Show
Abel Varga added a comment - Please close, as looking through the tests it seems it works, so the `lein-cljsbuild` might be out of date on this dep.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: