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

--experimental-resolve-self and exports sugar #30602

Closed
guybedford opened this issue Nov 22, 2019 · 8 comments
Closed

--experimental-resolve-self and exports sugar #30602

guybedford opened this issue Nov 22, 2019 · 8 comments
Labels
confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation. good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.

Comments

@guybedford
Copy link
Contributor

Currently when using the --experimental-resolve-self flag, with the following:

{
  "name": "test",
  "exports": "./test.js"
}

If including a require('test') in the test.js file and running node --experimental-resolve-self pkg/test.js this will throw an error.

It works with "main" and exports subpaths though so may be a sugar-specific or main-specific error case for this flag.

@guybedford guybedford added esm Issues and PRs related to the ECMAScript Modules implementation. good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. labels Nov 22, 2019
@DerekNonGeneric
Copy link
Contributor

DerekNonGeneric commented Nov 26, 2019

@guybedford, wouldn't that reference form a circularity? I believe the main module would need to export something that would be used by test.js. Also, can you please post the actual error message and version of Node?

Enable latest experimental modules features (currently --experimental-conditional-exports and --experimental-self-resolve).

The part in the Command Line Options page in the documentation says that it enables some flags, but that's wrong. What it should say is that it allows you to use the flags.

Also, the second flag it lists has a really big typo. --experimental-self-resolve should be --experimental-resolve-self; the words are misarranged. I will open another issue about this.

DerekNonGeneric pushed a commit to DerekNonGeneric/node-30602 that referenced this issue Nov 26, 2019
@DerekNonGeneric
Copy link
Contributor

@guybedford, I was not able to reproduce this bug. Please see DerekNonGeneric/node-30602 and reconfirm. I should note that if the index.js file were removed, it wouldn't work. Probably because then the package wouldn't have a main module.

DerekNonGeneric pushed a commit to DerekNonGeneric/node-30602 that referenced this issue Nov 26, 2019
@guybedford
Copy link
Contributor Author

guybedford commented Nov 26, 2019 via email

@DerekNonGeneric
Copy link
Contributor

DerekNonGeneric commented Nov 26, 2019

You need a require(‘test’) in the file as described.

https://github.com/DerekNonGeneric/node-30602/blob/master/test.js#L1

Still no error.

[...] node --experimental-resolve-self pkg/test.js

Your command is for pkg/test.js, though. 😕

@guybedford
Copy link
Contributor Author

@DerekNonGeneric you need to remove the index.js file. Please spend more time checking this stuff next time before pushing it back to me.

@DerekNonGeneric
Copy link
Contributor

@DerekNonGeneric you need to remove the index.js file.

😅 I mentioned that it needed an index.js to work in #30602 (comment).

Anyways, after removing index.js, the same error below appears both with and without sugar.

> node --experimental-resolve-self test.js

internal/modules/cjs/loader.js:957
    throw err;
    ^

Error: Cannot find module 'test'
Require stack:
- /mnt/c/apps/node-30602/test.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:954:17)
    at Function.Module._load (internal/modules/cjs/loader.js:847:27)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (/mnt/c/apps/node-30602/test.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:67:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/mnt/c/apps/node-30602/test.js' ]
}

This coincides with the "MODULE_NOT_FOUND" error described in #30633. Removing the "." key yields the following error.

node --experimental-modules ./test/test-constants.mjs
(node:6768) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/esm/default_resolve.js:94
  let url = moduleWrapResolve(specifier, parentURL);
            ^

Error: Cannot find package 'lorem' imported from /mnt/c/apps/lorem-demo/test/test-constants.mjs
    at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:94:13)
    at Loader.resolve (internal/modules/esm/loader.js:74:33)
    at Loader.getModuleJob (internal/modules/esm/loader.js:148:40)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:41:40)
    at link (internal/modules/esm/module_job.js:40:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

All that's left to do is double-check that this is working according to how the spec is written. If I find a discrepancy, I'll bring it up in the other issue that mentions this.

@guybedford
Copy link
Contributor Author

The bug, that this issue is tracking, is that exports to a string should be the main for both CJS and ESM.

@guybedford guybedford added the confirmed-bug Issues with confirmed bugs. label Dec 7, 2019
@guybedford
Copy link
Contributor Author

Fixed in #31009.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation. good first issue Issues that are suitable for first-time contributors. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.
Projects
None yet
Development

No branches or pull requests

2 participants