Jump to content

Import error using Typescript + web-dev-server to resolve bare imports


SantosR
 Share

Recommended Posts

I just updated to v6.2.0 and I am now trying to get bare imports working with web-dev-server.  I'm sorry if it's a bit out of PIXI scope, but I believe others using this library might run or have ran into the same problem. 

I'm running into this error coming from @pixi/polyfill package as it tries to import the object-assign dependency:

polyfill.js:9 Uncaught SyntaxError: The requested module './../../../../object-assign/index.js' does not provide an export named 'default'


Apparently the problem is with the "export ="  syntax being used in that dependency. Any guidance on how to deal with this issue?

Thanks in advance,

Link to comment
Share on other sites

25 minutes ago, Shukant Pal said:

You need to set `esModuleInterop` to true in your TypeScript configuration. See https://stackoverflow.com/questions/56238356/understanding-esmoduleinterop-in-tsconfig-file#56348146

It's already set to true. I saw documentation on typescriptlang.org specifying that esModuleInterop is required for export default to work. The problem here seems to be that the dependency is using export = instead of export default.

Edited by SantosR
Link to comment
Share on other sites

I fixed it with a web-dev-server rollup plugin to convert CommonJS to es6, using these settings:

 

import { fromRollup } from '@web/dev-server-rollup';
import rollupCommonjs from '@rollup/plugin-commonjs';

const commonjs = fromRollup(rollupCommonjs);

export default {
  plugins: [
    commonjs({
      include: [
        // the commonjs plugin is slow, list the required packages explicitly:
        '**/node_modules/object-assign/**/*',
        '**/node_modules/url/**/*',
        '**/node_modules/eventemitter3/**/*',
        '**/node_modules/earcut/**/*',
        '**/node_modules/punycode/**/*',
        '**/node_modules/querystring/**/*',
      ],
    }),
  ],
};

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...