javascriptangularstencils

Js file inside node_modules is not accessible to index.html


I am playing with stencil What I have done so far:

  1. Created a component in stencil
  2. Published it to the npm
  3. Created a angular project
  4. Installed stencil component to the angular project
  5. Added component.js file to the index.html file

When I am adding

<script src="/node_modules/stencil-poc-ng/dist/mycomponent.js"></script>

then brower console giving the following error:

GET http://localhost:4200/node_modules/stencil-poc-ng/dist/mycomponent.js 404 (Not Found) localhost/:1 Refused to execute script from 'http://localhost:4200/node_modules/stencil-poc-ng/dist/mycomponent.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.


Solution

  • You are building an Angular app, it won't be able to access a local path on your computer when running on your browser. What Angular ng servedoes:

    Only the "in memory" files are served, then your http://localhost:4200/node_modules/stencil-poc-ng/dist/mycomponent.js will always be invalid

    You have only two options left: