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

WIP Make CJS suggestions when file ext is not provided #30699

Closed
wants to merge 2 commits into from

Conversation

juanarbol
Copy link
Member

@juanarbol juanarbol commented Nov 28, 2019

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included

@juanarbol juanarbol marked this pull request as ready for review December 4, 2019 05:07
@juanarbol
Copy link
Member Author

This is breaking a test, this one test/message/esm_loader_not_found.mjs

// test/message/esm_loader_not_found.mjs
// Flags:  --experimental-loader i-dont-exist
import '../common/index.mjs';
console.log('This should not be printed');

Script:
$ ./node --experimental-loader i-dont-exist test/message/esm_loader_not_found.mjs

Output:

(node:43614) ExperimentalWarning: The ESM module loader is experimental.
(node:43614) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
internal/modules/esm/default_resolve.js:102
    url = moduleWrapResolve(specifier, parentURL);
          ^

Error: Cannot find package 'i-dont-exist' imported from /Users/juanjose/Documents/GitHub/Node/node/
    at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:102:11)
    at Loader.resolve (internal/modules/esm/loader.js:73:33)
    at Loader.getModuleJob (internal/modules/esm/loader.js:147:40)
    at Loader.import (internal/modules/esm/loader.js:131:28)
    at internal/process/esm_loader.js:63:31
    at Object.initializeLoader (internal/process/esm_loader.js:67:5)
    at runMainESM (internal/modules/run_main.js:41:20)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:64:5)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_MODULE_NOT_FOUND'
}

No idea why. I'm stuck on this.

@guybedford
Copy link
Contributor

That's correct - ./tools/test.py test/message/esm_loader-not_found.mjs should compare the output to https://github.com/nodejs/node/blob/master/test/message/esm_loader_not_found.out and pass the test.

@juanarbol
Copy link
Member Author

juanarbol commented Dec 4, 2019

Jm, I get it, but the thing is that test script is returning error, that output is the only error. I mean, make test is not passing.

@guybedford
Copy link
Contributor

Message tests will always provide a diff when there's an error. A stack line might change then the .output file can be updated.

@juanarbol
Copy link
Member Author

Aaaah, you say, it's a diff between .output file and my output?

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea behind this. It does require a test case though.

@juanarbol
Copy link
Member Author

I'm try to write that test

@juanarbol juanarbol mentioned this pull request Dec 18, 2019
4 tasks
@BridgeAR
Copy link
Member

Ping @juanarbol

@BridgeAR BridgeAR added module Issues and PRs related to the module subsystem. wip Issues and PRs that are still a work in progress. labels Dec 24, 2019
import '../common/index.mjs';

import('../fixtures/es-modules/cjs')
.catch(err => console.error(err))
Copy link
Member Author

@juanarbol juanarbol Dec 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR I'm having a issue here, when I run ./node test/es-modules/this-test.mjs does not work the CJS stuff, but when I change my cd to test/es-modules, and run ../../node this-test.mjs it works, you have any suggestions or something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nodejs/modules-active-members PTAL

@bmeck
Copy link
Member

bmeck commented Jan 2, 2020

I like the error suggestions, but at least per files without an extension this is no longer true per #31021 try using a file like https://github.com/nodejs/node/blob/master/test/fixtures/es-modules/package-type-module/extension.unknown for your test fixture instead

@BridgeAR
Copy link
Member

Ping @juanarbol

@juanarbol
Copy link
Member Author

Sorry, the ES Module implementation has changed like a lot, I'll take more time to migrate this to the new implementation, seems harder than before, but with some time this could be done.

@juanarbol
Copy link
Member Author

I'll close this, and spend some time to understand the new loader then open another PR; sorry

@juanarbol juanarbol closed this Mar 2, 2020
@juanarbol juanarbol deleted the esmod-as-cjmodule branch January 19, 2021 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem. wip Issues and PRs that are still a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants