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.

Angular v10 issue with vendor packages

See original GitHub issue

Describe the bug Storybook does not load ES2015 bundles, leading to runtime errors in Angular v10 applications.

  • Starting from v10, Angular ships only ES2015 bundles.
  • Libraries typically ship both ES5 and ES2015 modules to remain compatible with Angular v8 and 9 (see APFv8, APFv10).
  • Storybook does not include “es2015” entry points (note that supportES2015 is always set to false) in the loader config.
  • As a result, Angular is loaded as ES2015 and third-party libraries as ES5, leading to run-time errors such as functions attempting to extend classes.

To Reproduce

  1. Clone https://github.com/tsvetomir/ka-grid-1474492
  2. Run npm ci in grid-app
  3. Run npm run storybook
  4. See error in browser console:
ERROR TypeError: class constructors must be invoked with 'new'
    ZoneAwareEventEmitter http://localhost:6006/vendors~main.f0580120cc2429d3a759.bundle.js:111214
    GridComponent http://localhost:6006/vendors~main.f0580120cc2429d3a759.bundle.js:117347
    createClass http://localhost:6006/vendors~main.f0580120cc2429d3a759.bundle.js:62526

The example uses the Kendo UI Grid, but presumably the issue is not limited to it.

Expected behavior The Storybook app should load ES2015 bundles, whenever available.

Screenshots image

System:

  System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
  Binaries:
    Node: 10.19.0 - /usr/local/bin/node
    Yarn: 1.21.1 - ~/.yarn/bin/yarn
    npm: 6.14.5 - ~/.npm/bin/npm
  Browsers:
    Chrome: 83.0.4103.116
    Firefox: 77.0.1
    Safari: 13.1.1
  npmPackages:
    @storybook/angular: ^5.3.19 => 5.3.19 

Additional context The problem can be worked around by overriding the Webpack configuration in .storybook/webpack.config.js.

const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = async ({ config }) => {
  const mainFields = [
    'es2015',
    'browser',
    'module',
    'main',
  ];

  config.resolve.plugins = [new TsconfigPathsPlugin({
    configFile: 'tsconfig.app.json',
    mainFields
  })];

  config.resolve.mainFields = mainFields;

  return config;
};

See the fix-modules branch for a runnable demo with this workaround.

Originally reported by @aishwaryasharma14

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
nicolae536commented, Apr 6, 2021

Thanks for tips @shilman . I managed to fix it by changing this -> I also updated to latest version. In storybook/tsconfig.json

{
  "extends": "../src/tsconfig.app.json",
  "compilerOptions": {
    "target": "ES6", -> Target "ES6" seems to work
    "types": [
      "node"
    ]
  },
  "lib": [
    "es2017",
    "es2018",
    "es2019",
    "dom"
  ],
  "exclude": [
    "../src/test.ts",
    "../src/**/*.spec.ts",
    "../src/service-worker/**/*",
    "../src/app/**/*",
    "../src/test-helpers/**/*"
  ],
  "include": [
    "../src/libs/**/*",
  ],
  "files": [
    "./typings.d.ts"
  ]
}

0reactions
shilmancommented, Apr 6, 2021

@nicolae536 Try upgrading to 6.2. We just released a bunch of improvements there.

npx sb upgrade
Read more comments on GitHub >

github_iconTop Results From Across the Web

Providing dependencies in modules - Angular
A provider is an instruction to the Dependency Injection system on how to obtain a value for a dependency. Most of the time,...
Read more >
NG0201: No provider for {token} found! - Angular
You see this error when you try to inject a service but have not declared a corresponding provider. A provider is a mapping...
Read more >
Building and serving Angular apps
This page discusses build-specific configuration options for Angular projects. Configuring application environmentslink. You can define different named ...
Read more >
Angular workspace configuration
Resolve vendor packages source maps. boolean, false. hidden, Output source maps used for error reporting tools. boolean, false ...
Read more >
ng build - Angular
Option Description Value Type Default Value ‑‑aot Build using Ahead of Time compilation. boolean true ‑‑base‑href Base url for the application being built. string ‑‑delete‑output‑path Delete...
Read more >

github_iconTop Related Medium Post

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