rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

es6-global can't resolve external node modules as URI

Open yyc-git opened this issue 8 years ago • 6 comments

build this code:

external createSandbox : unit => Js.t {..} = "create" [@@bs.scope "sandbox"] [@@bs.module "sinon"];

expect to genearte:

import * as Sinon                  from "../../node_modules/sinon";

but actual to generate:

/*
wrong:
 import * as Sinon                  from "sinon"; 
*/

/* fixed */
import * as Sinon  from "../../node_modules/sinon/dist/sinon.js"

refer to #1193:

how to know the path of external JS library, currently we leave it as it Implementation details: we might need have a global view of dependencies and pass a package map unlike current implementation which did lots of path calculation

can @bobzhang fix it?

yyc-git avatar Oct 14 '17 03:10 yyc-git

what's your motivation here? note your third party js dependency probably does not work with browser out of box (even with es6 module support). for example, in browser, you have to write from "./xxx.js" instead of from "./xxx"

bobzhang avatar Oct 14 '17 12:10 bobzhang

I want to use es6 module in chrome, so that i don't need to rollup the bundle before run in chrome.

yes, the "expect to generate" is wrong here, the actual expect is like:

import * as Sinon  from "../../node_modules/sinon/dist/sinon.js"; 
/* get "dist/sinon.js" path from sinon->pacakge.json->main field */

yyc-git avatar Oct 14 '17 12:10 yyc-git

👍 I'd like to see this too. Right now I have to make some nasty manual file transformations in order to get my local environment to work properly.

bloodyowl avatar May 27 '20 16:05 bloodyowl

Still not solved? I'm having this issue when using Reason+React, and importing React through CDN.

olleharstedt avatar Nov 06 '20 00:11 olleharstedt

+1 - It would be nice to be able to work on a React project without dev-time bundling.

I was working on a small project in the browser with es6-global and it was excellent until I added React. I ended up changing that setting to es6 and now use ESBuild to do the bundling, like this:

yarn run esbuild src/ui/EntryPoint.js --bundle --outfile=build/out.js

(Maybe someone will find this helpful)

EDIT: I have since removed ESBuild in favor of import maps in my index.html:

    <script type="importmap">
      {
        "imports": {
          "react": "https://esm.sh/react@17",
          "react-dom": "https://esm.sh/react-dom@17"
        }
      }
    </script>

jmezzacappa avatar Jul 27 '21 18:07 jmezzacappa

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 15 '23 06:10 stale[bot]