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.

import "mod" in api_esm.mjs leads to crash if bundling with webpack

See original GitHub issue

Hi, I am bundling Chevrotain with Webpack in my Argdown language-server. This currently creates a lot of the following warnings:

WARNING in ../argdown-core/node_modules/chevrotain/lib_esm/api_esm.mjs 11:27-42
export 'default' (imported as 'mod') was not found in '../lib/src/api.js' (possible exports: Alternation, Alternative, CstParser, EMPTY_ALT, EOF, EarlyExitException, EmbeddedActionsParser, GAstVisitor, Lexer, LexerDefinitionErrorType, MismatchedTokenException, NoViableAltException, NonTerminal, NotAllInputParsedException, Option, Parser, ParserDefinitionErrorType, Repetition, RepetitionMandatory, RepetitionMandatoryWithSeparator, RepetitionWithSeparator, Rule, Terminal, VERSION, __esModule, clearCache, createSyntaxDiagramsCode, createToken, createTokenInstance, defaultLexerErrorProvider, defaultParserErrorProvider, isRecognitionException, serializeGrammar, serializeProduction, tokenLabel, tokenMatcher, tokenName)

So Webpack uses the ESM Version for bundling and does not find the default export from lib/src/api.js that is imported in api_esm.mjs. Ignoring the warnings and testing the language-server by starting the Argdown VSCode extension leads to an immediate crash.

If I make the following change in the first line of api_esm.mjs, the warnings during the build process disappear and the language server no longer crashes:

import * as mod from "../lib/src/api.js";

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
christianvoigtcommented, Nov 10, 2021

Hi again, I finally solved my webpack issues today and quickly wanted to report my findings. The problem was caused by my webpack.config.js. For some reason (unknown to me) it contained the following problematic module rule:

  module: {
    rules: [
      {
        test: /\.mjs$/,
        type: "javascript/auto",
      },
     ]
   }

Removing this rule or changing the type to javascript/esm fixed the bundling issues with chevrotain.

0reactions
bd82commented, Oct 9, 2021

I will close this for now. Feel free to re-open if needed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack-bundled code crashes when both `import` and ...
Our Webpack bundle contains placeholders for the dynamic import of icons. An example dynamic import is as follows:
Read more >
Externals - webpack
Prevent bundling of certain import ed packages and instead retrieve these external dependencies at runtime. For example, to include jQuery from a CDN ......
Read more >
Introduction to Webpack. Module bundling, Loaders, Plugins…
Webpack is a module bundler for modern JavaScript applications. The import and export statements have been standardized in ES2015. They are not supported...
Read more >
Bundlers | SheetJS Community Edition
SheetJS predates ECMAScript modules and bundler tools like Webpack. ... The xlsx.mjs source file are written in a subset of ES6 that esbuild...
Read more >
webpack on twitter.com
If you have 15 minutes, this “Webpack from First Principles” screencast ... For loading and bundling JS files, we used two libraries: loadrunner...
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