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

import library as module in website #5872

Closed
inouiw opened this issue Nov 1, 2020 · 1 comment
Closed

import library as module in website #5872

inouiw opened this issue Nov 1, 2020 · 1 comment

Comments

@inouiw
Copy link

inouiw commented Nov 1, 2020

Feature Request

Maybe this is already possible.

Is your feature request related to a problem? Please describe.
I want to use the library as a module in my web page.
If I use "<script type="module" src="https://unpkg.com/rxjs/bundles/rxjs.umd.min.js"></script>"
I get the error:

1st error

Input_0:2259 Uncaught TypeError: Cannot set property 'rxjs' of undefined
    at Input_0:2259
    at Input_0:2259

If I install the library via npm and then, for testing purposes, use
import * as rxjs from "/node_modules/rxjs/_esm2015/index.js";
then I get a list of errors as the following:

2nd error

(some lines excluded)
index.js:47 GET http://localhost:8080/node_modules/rxjs/_esm2015/internal/observable/range net::ERR_ABORTED 404 (Not Found)
index.js:48 GET http://localhost:8080/node_modules/rxjs/_esm2015/internal/observable/throwError net::ERR_ABORTED 404 (Not Found)
index.js:49 GET http://localhost:8080/node_modules/rxjs/_esm2015/internal/observable/timer net::ERR_ABORTED 404 (Not Found)
index.js:50 GET http://localhost:8080/node_modules/rxjs/_esm2015/internal/observable/using net::ERR_ABORTED 404 (Not Found)
index.js:51 GET http://localhost:8080/node_modules/rxjs/_esm2015/internal/observable/zip net::ERR_ABORTED 404 (Not Found)
index.js:52 GET http://localhost:8080/node_modules/rxjs/_esm2015/internal/scheduled/scheduled net::ERR_ABORTED 404 (Not Found)
index.js:55 GET http://localhost:8080/node_modules/rxjs/_esm2015/internal/config net::ERR_ABORTED 404 (Not Found)
localhost/:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
localhost/:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

My explanation for the first error is that rxjs.umd.min.js does not support modules.
My explanation for the second error is, that the file /node_modules/rxjs/_esm2015/index.js references './internal/observable/range' and when the browser requests this file it does not automatically add .js so the file is not found.

I tried adding .js to all imports in _esm2015/index.js, and then these were found but I would have to do this recursively for all subfolders.

Describe the solution you'd like
What I tried, is it already possible and I am just doing something wrong? If not, is there a plan to implement it or are there better alternatives.

Describe alternatives you've considered

(If this is new operator request) describe reason it should be core operator
For projects just using modern browsers I think using import should be the preferred solution

Additional context
I used Chrome browser and http-server.

@kwonoj
Copy link
Member

kwonoj commented Nov 1, 2020

Dupe of #4416

@kwonoj kwonoj closed this as completed Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants