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

ES6 module import has been broken by #3774 #3859

Closed
ert78gb opened this issue Aug 4, 2023 · 2 comments · Fixed by #3858
Closed

ES6 module import has been broken by #3774 #3859

ert78gb opened this issue Aug 4, 2023 · 2 comments · Fixed by #3858

Comments

@ert78gb
Copy link
Contributor

ert78gb commented Aug 4, 2023

Description of the bug/issue

Our projects use es6 module. Upgrading nightwatch 3.0.1 => 3.1.0 our test are failed.
The reason is the typescript does not transpile correctly the lib/utils/requireModule.js file.
The typescript compilation had been introduced with #3774 PR
The issue is still exists in the 3.1.2 version

The bogus transpiled code

if (getNodeVersion() >= 14) {
    const { pathToFileURL } = require('node:url');
    return Promise.resolve(`${pathToFileURL(fullpath).href}`).then(s => __importStar(require(s))).then(result => {
        const _default = result.default || {};
        return Object.keys(result).reduce((prev, val) => {
            if (val !== 'default') {
                prev[val] = result[val];
            }
            return prev;
        }, _default);
    });
}

The __importStar(require(s)) the typescript version uses the require.

I tried

  • upgrade typescript to 5.1.6 but it did not help
  • the "esModuleInterop": false typescript compiler option did not help

The only solution that came into my mind is copy the file to the dist folder after the ts build in the postbuild script.
The PR that I opened #3858
I hope you will find smarter solution.

Steps to reproduce

  1. Go to '...'
  2. Click on '...'
  3. Scroll down to '...'
  4. See error

Sample test

No response

Command to run

No response

Verbose Output

No response

Nightwatch Configuration

No response

Nightwatch.js Version

3.1.0

Node Version

No response

Browser

No response

Operating System

No response

Additional Information

No response

@ert78gb ert78gb mentioned this issue Aug 4, 2023
8 tasks
@garg3133
Copy link
Member

garg3133 commented Aug 7, 2023

@ert78gb Based on the discussion in microsoft/TypeScript#43329, I think changing module config in tsconfig.json to Node16 would be the right way to fix this.

Additional info on the change:

@ert78gb
Copy link
Contributor Author

ert78gb commented Aug 7, 2023

@garg3133 Thx. I updated the PR. It solves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants