question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested `default` exports with using dynamic import

See original GitHub issue
  • @testing-library/user-event version: 13.5.0
  • Testing Framework and version: Vitest v0.0.106
  • DOM Environment: None

Relevant code or config

When using Node’s native dynamic import, nested default is exported, causing the resolving to fail. Related https://github.com/vitest-dev/vitest/issues/243

➜ node            
Welcome to Node.js v16.13.0.
Type ".help" for more information.
> const a = await import('@testing-library/user-event')
undefined
> a
[Module: null prototype] {
  __esModule: true,
  default: {
    default: {
      click: [Function: click],
      dblClick: [Function: dblClick],
      type: [Function: type],
      clear: [Function: clear],
      tab: [Function: tab],
      hover: [Function: hover],
      unhover: [Function: unhover],
      upload: [Function: upload],
      selectOptions: [Function: bound selectOptionsBase],
      deselectOptions: [Function: bound selectOptionsBase],
      paste: [Function: paste],
      keyboard: [Function: keyboard]
    },
    specialChars: [Getter]
  },
  specialChars: {
    arrowLeft: '{arrowleft}',
    arrowRight: '{arrowright}',
    arrowDown: '{arrowdown}',
    arrowUp: '{arrowup}',
    enter: '{enter}',
    escape: '{esc}',
    delete: '{del}',
    backspace: '{backspace}',
    home: '{home}',
    end: '{end}',
    selectAll: '{selectall}',
    space: '{space}',
    whitespace: ' ',
    pageUp: '{pageUp}',
    pageDown: '{pageDown}'
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ph-fritschecommented, Dec 30, 2021

Resolved in v14.0.0-beta.4. I hope the solution “just works” for everybody.

1reaction
sheremet-vacommented, Dec 22, 2021

This is pure ESM Node without any transpilers: https://stackblitz.com/edit/node-mucfca?file=index.js

I’m not sure if exports.default is correct representation of default export. Isn’t it module.exports? Maybe you need to update your bundling proccess?

I think bundlers tried to support this way of exporting default, but official implementation doesn’t. Babel has a lot of experimental things that didn’t end up in Node/browsers and the whole point of using babel is to make it run everywhere 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - export default <Class> exports double nested default
I solved my problem by creating a variable inside the class I want to use my import. something like this: export default class ......
Read more >
Nested Imports in Meteor - zodern
Nested imports should not be confused with dynamic imports. Dynamic imports delay downloading a file until it is needed. In contrast, the files...
Read more >
Demistifying webpack's 'import' function: using dynamic ...
In this article we will learn about demistifying webpack's 'import' function: using dynamic arguments. Although it is a popular selling point ...
Read more >
Dynamic import() Expressions in TypeScript - Marius Schulz
TypeScript 2.4 added support for dynamic import() expressions, which allow you to asynchronously load and execute ECMAScript modules on demand.
Read more >
Dynamic imports in Next.JS - Medium
Dynamic imports, unlike regular imports, are flexible about when and how the modules are imported, hence improving the page load time. In ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found