Skip to content

'Element' is not exported #2563

Closed
Closed

Description

@mmakrzem

Stencil version:

I'm submitting a:

[X] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
I tried to upgrade to the latest version of Stencil however I'm getting the following error:

[ ERROR ]  Rollup: Missing Export: ./src/components/accordion/accordion.tsx:2:20
       'Element' is not exported by ./node_modules/@stencil/core/internal/client/index.mjs?app-data=conditional,
       imported by ./src/components/accordion/accordion.tsx

  L1:  import {
  L2:    Component, Element, Event, EventEmitter, forceUpdate, h, JSX, Method
  L3:  } from '@stencil/core';

[23:22.4] build failed, watching for changes... in 8.68 s

Expected behavior:
I'm upgrading from stencil @1.9.2 where everything worked just fine. It seems like I can only upgrade to stencil @1.13.0 where everything works, but as soon as I jump to v1.14 or higher then I get this error saying that Element is no longer exported.

Steps to reproduce:

To reproduce,

import { Element } from '@stencil/core'

Activity

  1. Trendy commented on Jul 9, 2020

    @Trendy

    I'm experiencing a similar issue, but with Event instead of Element. It started happening after upgrading from 1.12.2

  2. chrisweight commented on Jul 16, 2020

    @chrisweight

    I'm experiencing a similar issue, but with Event instead of Element. It started happening after upgrading from 1.12.2

    I'm having exactly the same issue with Event on 1.16.2 - I'm guessing this is down to the rollup dependency bump to 2.x

  3. valentinmirchev commented on Jul 24, 2020

    @valentinmirchev

    I'm experiencing the same Event problem with version 1.16.5

  4. Trendy commented on Aug 12, 2020

    @Trendy

    Sorry it took me so long to come back around to this, but I solved my issue, it looks like someone had used Event as a constructor in a file somewhere, and this really confused roll up.

    // Offending code example
    this.textarea.dispatchEvent(new Event('input));
    

    Not entirely sure how it was slipped into the code base, but cleaning that up fixed my issue

  5. mmakrzem commented on Sep 9, 2020

    @mmakrzem
    Author

    My workaround to the problem is to remove 'Element' from the import statement and instead add the following to the source code where the import fails:

    interface ElementDecorator {
      () : PropertyDecorator;
    }
    declare const Element : ElementDecorator;
    
  6. mmakrzem commented on Sep 9, 2020

    @mmakrzem
    Author

    It is strange because I have a bunch of stencil components that use:

     import { Element } from '@stencil/core'
    

    but only the first component is failing.... If I add the workaround code shown above to the first component file, then everything works, and I don't have to change any of the Element imports in any of my other component files.

  7. adrian2x commented on Sep 13, 2020

    @adrian2x

    I'm getting that same error with Event on 2.0.3:

    Rollup: Missing Export: ./src/global/store.ts:7:9
               'Event' is not exported by ./node_modules/@stencil/core/internal/client/index.js?app-data=conditional,
               imported by ./src/global/store.ts
    
  8. Krzyrok commented on Nov 24, 2020

    @Krzyrok

    #2563 (comment)
    On [email protected] I had the same issue with error when importing Event decorator. The reason in my case was rename during import:

    import {
      Event as EventProp
    } from '@stencil/core';
    

    Removing this rename solved the issue:

    import {
      Event
    } from '@stencil/core';
    

    (but I cannot use Event from global typings in the same file now...)

  9. claviska commented on Nov 24, 2020

    @claviska
    Contributor

    Sorry it took me so long to come back around to this, but I solved my issue, it looks like someone had used Event as a constructor in a file somewhere, and this really confused roll up.

    // Offending code example
    this.textarea.dispatchEvent(new Event('input));
    

    Not entirely sure how it was slipped into the code base, but cleaning that up fixed my issue

    This is indeed the cause of this error, at least in every case I've seen it. A workaround is posted above but another one is to rename the import:

    import { Event as ComponentEvent, EventEmitter } from `@stencil/core`
    
    ...
    
    @ComponentEvent() yourEvent: EventEmitter;
  10. dougestey commented on Nov 30, 2020

    @dougestey

    I am still experiencing this issue.

    Using an import alias import { Event as ComponentEvent } from '@stencil/core' causes:

    [51:56.4]  generate custom elements bundle finished in 8.61 s
    
    [ ERROR ]  Rollup: Missing Export: ./src/components/button/button.tsx:12:29
               'Event' is not exported by
               ./node_modules/@stencil/core/internal/client/index.js?app-data=conditional, imported by
               ./src/components/button/button.tsx
    [51:56.4]  build failed in 11.21 s
    

    Stencil version 2.3.0.

  11. lufonius commented on May 20, 2021

    @lufonius

    this error is shown to me when i change the srcDir option in the config to anything else than src.

    stencil version: 2.5.2
    reproduce:

    • npm init stencil
    • rename folder src to
    • adjust srcDir option to
    • npm run start

    what works though if you set the srcDir option to something like src/webcomponents, and adjust the srcDir config option accordingly.

  12. lufonius commented on May 20, 2021

    @lufonius

    ah i just found out ... faster than i expected :)

    adjusting only the srcDir option is not enough, in the tsconfig.json the include section must also be changed.
    change
    "include": [ "src" ],

    to

    "include": [ "webcomponents" ],

    now the error makes sense. would be nice to mention it in the docs under the config srcDir option.

  13. aztack commented on Jun 28, 2021

    @aztack

    same problem here:

    Rollup: Missing Export: ./src/components/tree-item.tsx:7:25
               'Element' is not exported by
               ./node_modules/@stencil/core/internal/client/index.js?app-data=conditional, imported by
               ./src/components/tree/tree-item.tsx
    
    {
      "dependencies": {
        "@stencil/core": "^2.6.0",
        "@stencil/stylus": "^1.0.1"
      }
    }
  14. kerryj89 commented on Apr 10, 2022

    @kerryj89

    Ran into this when upgrading components from Stencil 1 to Stencil 2.

    There were some conditionals in the components like:

    if (foo && foo instanceof Element) { ... }
    

    Changing Element to window.Element seemed to fix this, i.e.

    if (foo && foo instanceof window.Element) { ... }
    
  15. hettiger commented on Jan 16, 2023

    @hettiger
    Contributor

    Still ran into this. I wonder why this has been closed …

    However, I found a workaround:

    /**
     * Workaround to allow for Stencil `Element` decorator usage while still having access to the DOM Element type.
     */
    export const DOMElement = Element;
    export interface DOMElement extends Element {}
    

    Simply import these from anywhere in your app. Then use DOMElement instead of Element. (except for the actual @element() decorator usage ofc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions