Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: scriptElm is undefined #2500

Closed
vandres opened this issue Jun 10, 2020 · 4 comments
Closed

TypeError: scriptElm is undefined #2500

vandres opened this issue Jun 10, 2020 · 4 comments
Labels
ionitron: needs reproduction This PR or Issue does not have a reproduction case URL ionitron: stale issue This issue has not seen any activity for a long period of time

Comments

@vandres
Copy link

vandres commented Jun 10, 2020

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 am using Stencil just for components. I include my scripts in a server side technology (Twig) to bind the asset cache to the template cache there:

<script type="module" src="/static/js/voan/voan.esm.{{ versionString }}js"></script>
<script nomodule src="/static/js/voan/voan.{{ versionString }}js"></script>

Then there is an .htaccess, which rewrites these files to the normal filename.

Having this setup, I always get the error message TypeError: scriptElm is undefined, which comes from this code:

const scriptElm = BUILD.scriptDataOpts || BUILD.safari10 || BUILD.dynamicImportShim
        ? Array.from(doc.querySelectorAll('script')).find(s => new RegExp(`\/${NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) || s.getAttribute('data-stencil-namespace') === NAMESPACE)
        : null;
    const importMeta = "";
    const opts = BUILD.scriptDataOpts ? scriptElm['data-opts'] || {} : {};
    if (BUILD.safari10 && 'onbeforeload' in scriptElm && !history.scrollRestoration /* IS_ESM_BUILD */) {

Is there anyway to include these JS files the way I do? In Version 1.9.2 this technique was working.

@ionitron-bot ionitron-bot bot added the triage label Jun 10, 2020
@KevinCarnaille2
Copy link

KevinCarnaille2 commented Sep 29, 2021

I don't know if you fixed your problem (hope so) but for other people facing this kind of issue :
The reason : the RegExp \/${NAMESPACE}(\\.esm)?\\.js($|\\?|#) doesn't match your script src, as you have added a versionString in the middle of the whole src attribute.

If you look closely into the snippet vandres gave us, you have a fallback (not officially documented ?) :

... || s.getAttribute('data-stencil-namespace') === NAMESPACE

For me, adding the data-stencil-namespace="your-namespace" attribute to my script tag fixed the problem.

@rwaskiewicz
Copy link
Member

Hey folks 👋

I apologize that it took so long for someone on the team to respond to this issue.

There are two ways scriptElm could be undefined||null. I believe we patched the case where scriptElm could be null in #4101. However, I do believe that @KevinCarnaille2 is correct here & has an open issue to get 'data-stencil-namespace' documented.

Given this took so long for the team to respond to, if this is still an issue, and anyone is willing/able to create a minimal reproduction case for the team to take a look at, we'd greatly appreciate it. In the mean time, I've tagged ionic-team/stencil-site#777 to get it ingested into our backlog.

Thanks!

@rwaskiewicz rwaskiewicz added the ionitron: needs reproduction This PR or Issue does not have a reproduction case URL label Apr 3, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Apr 3, 2023

Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

Please reproduce this issue in an Stencil starter component library and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

For a guide on how to create a good reproduction, see our Contributing Guide.

@ionitron-bot ionitron-bot bot removed the triage label Apr 3, 2023
@ionitron-bot ionitron-bot bot added the ionitron: stale issue This issue has not seen any activity for a long period of time label May 3, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented May 3, 2023

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.

Thank you for using Stencil!

@ionitron-bot ionitron-bot bot closed this as completed May 3, 2023
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ionitron: needs reproduction This PR or Issue does not have a reproduction case URL ionitron: stale issue This issue has not seen any activity for a long period of time
Projects
None yet
Development

No branches or pull requests

3 participants