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, 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-exportsand--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.
@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.
You need a require(‘test’) in the file as described. A circular reference
is used to make the test a single file.
On Tue, Nov 26, 2019 at 08:51 Derek Lewis notifications@github.com wrote:
@guybedford https://github.com/guybedford, I was not able to reproduce
this bug. Please see DerekNonGeneric/node-30602
https://github.com/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.—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/nodejs/node/issues/30602?email_source=notifications&email_token=AAESFSUI6NSSAI2GZNWVQZ3QVUSULA5CNFSM4JQVN5CKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFGCBEQ#issuecomment-558637202,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAESFSSBJQLCQHOGBBYZN3LQVUSULANCNFSM4JQVN5CA
.
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. 😕
@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 you need to remove the index.js file.
😅 I mentioned that it needed an index.js to work in https://github.com/nodejs/node/issues/30602#issuecomment-558637202.
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.
The bug, that this issue is tracking, is that exports to a string should be the main for both CJS and ESM.
Fixed in #31009.