Stencil: Unclear which JS file in dist should be used for Internet Explorer 11

Created on 7 Sep 2020  ยท  9Comments  ยท  Source: ionic-team/stencil

It seems there are 2 possible main files: index.js (which points to esm) and index.cjs.js. Neither is suited for IE 11. Documentation is lacking in this respect.

triage

Most helpful comment

The main problem is that nowhere in the docs we can find any explanation about the dist files.

What are all the p..entry.js files? Which files do we need? It is not well explained in the docs.

All 9 comments

As far as I can tell when used for the browser it should be:

  • module: /dist/<library-name>/<library-name>.esm.js
  • nomodule: /dist/<library-name>/<library-name>.js

When I create a new project components-lib with starter setting component, and install and build, my dist folder looks like this:

./dist
โ”œโ”€โ”€ [        224]  cjs
โ”‚ย ย  โ”œโ”€โ”€ [        726]  components-lib.cjs.js
โ”‚ย ย  โ”œโ”€โ”€ [      32970]  index-1e5bfcf5.js
โ”‚ย ย  โ”œโ”€โ”€ [         15]  index.cjs.js
โ”‚ย ย  โ”œโ”€โ”€ [        599]  loader.cjs.js
โ”‚ย ย  โ””โ”€โ”€ [        635]  my-component.cjs.entry.js
โ”œโ”€โ”€ [        192]  collection
โ”‚ย ย  โ”œโ”€โ”€ [        215]  collection-manifest.json
โ”‚ย ย  โ”œโ”€โ”€ [         96]  components
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ [        128]  my-component
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ [         28]  my-component.css
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ [       1682]  my-component.js
โ”‚ย ย  โ”œโ”€โ”€ [         11]  index.js
โ”‚ย ย  โ””โ”€โ”€ [         96]  utils
โ”‚ย ย      โ””โ”€โ”€ [        130]  utils.js
โ”œโ”€โ”€ [        192]  components-lib
โ”‚ย ย  โ”œโ”€โ”€ [        222]  components-lib.esm.js     <== note there is no file components-lib.js
โ”‚ย ย  โ”œโ”€โ”€ [          0]  index.esm.js              <== note this file is completely empty
โ”‚ย ย  โ”œโ”€โ”€ [        299]  p-0bdbdffa.entry.js
โ”‚ย ย  โ””โ”€โ”€ [       6031]  p-24d0f0ad.js
โ”œโ”€โ”€ [        128]  custom-elements
โ”‚ย ย  โ”œโ”€โ”€ [       1651]  index.d.ts
โ”‚ย ย  โ””โ”€โ”€ [       1102]  index.js
โ”œโ”€โ”€ [        256]  esm
โ”‚ย ย  โ”œโ”€โ”€ [        535]  components-lib.js
โ”‚ย ย  โ”œโ”€โ”€ [      32304]  index-a5c9c759.js
โ”‚ย ย  โ”œโ”€โ”€ [          1]  index.js
โ”‚ย ย  โ”œโ”€โ”€ [        517]  loader.js
โ”‚ย ย  โ”œโ”€โ”€ [        566]  my-component.entry.js
โ”‚ย ย  โ””โ”€โ”€ [        256]  polyfills
โ”‚ย ย      โ”œโ”€โ”€ [      94164]  core-js.js
โ”‚ย ย      โ”œโ”€โ”€ [      10382]  css-shim.js
โ”‚ย ย      โ”œโ”€โ”€ [      19514]  dom.js
โ”‚ย ย      โ”œโ”€โ”€ [        320]  es5-html-element.js
โ”‚ย ย      โ”œโ”€โ”€ [       1136]  index.js
โ”‚ย ย      โ””โ”€โ”€ [       4383]  system.js
โ”œโ”€โ”€ [         48]  index.cjs.js
โ”œโ”€โ”€ [         31]  index.js
โ””โ”€โ”€ [        224]  types
    โ”œโ”€โ”€ [         96]  components
    โ”‚ย ย  โ””โ”€โ”€ [         96]  my-component
    โ”‚ย ย      โ””โ”€โ”€ [        220]  my-component.d.ts
    โ”œโ”€โ”€ [       1510]  components.d.ts
    โ”œโ”€โ”€ [         48]  index.d.ts
    โ”œโ”€โ”€ [      57854]  stencil-public-runtime.d.ts
    โ””โ”€โ”€ [         96]  utils
        โ””โ”€โ”€ [         85]  utils.d.ts

13 directories, 34 files

So using components-lib/components-lib.esm.js for module capable browsers works fine. But the non-module version does not exist.

Having the same question here. With the stencil starter it also comes with this config:

    {
      type: 'dist',
      esmLoaderPath: '../loader',
    },

So I tried loading the index.js file in the generated loader folder, still no luck, browser gave me

Uncaught SyntaxError: Unexpected token 'export'

PS. Also tried loading it from dist/collection/components/my-component/my-component.js and browser gave me
Uncaught SyntaxError: Cannot use import statement outside a module

Stencil version: v2.0.3

Tried a build in v1.8.5 and both the my-component.esm.js and my-component.js files are there in the dist/my-component/ folder

Where can I find a Stencil project that works in Internet Explorer 11?

The main problem is that nowhere in the docs we can find any explanation about the dist files.

What are all the p..entry.js files? Which files do we need? It is not well explained in the docs.

The build for old browsers is disabled by default since v2 (https://github.com/ionic-team/stencil/blob/master/CHANGELOG.md#-200-2020-08-31).

here is the documentation to enable it https://stenciljs.com/docs/config-extras

OMG this link is gold.

For dist/ files, you have some informations here https://stenciljs.com/docs/publishing#package-json

dist-publish-documentation

This works.

In stencil.config.ts I've set buildEs5: true and the example extras settings.

After the build and firing up a local server in www, index.html loads www/build/project.js and the default "my-component" (so nothing fancy) works in IE 11, Edge 80, Safari 11.

I do suggest that you add this to the documentation, for example under "Guides" could be a topic "Older browsers", and existing page Browser support could link to there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anthonylebrun picture anthonylebrun  ยท  3Comments

ryanmunger picture ryanmunger  ยท  3Comments

guidoknoll picture guidoknoll  ยท  3Comments

mitchellsimoens picture mitchellsimoens  ยท  3Comments

lcswillems picture lcswillems  ยท  3Comments