bun icon indicating copy to clipboard operation
bun copied to clipboard

Implement package.json `"#imports"` field support

Open Jarred-Sumner opened this issue 2 years ago • 1 comments

Jarred-Sumner avatar Jul 09 '22 07:07 Jarred-Sumner

ref: https://nodejs.org/api/packages.html#imports

Mouvedia avatar Aug 06 '22 10:08 Mouvedia

Any ETA on this one?

phaistonian avatar Sep 19 '22 08:09 phaistonian

I would guess this is a big blocker for a lot of people. All my Node.js packages are using #imports so I can't try out Bun yet.

vjpr avatar Sep 19 '22 14:09 vjpr

This is implemented and will soon be available in the canary build of bun:

bun upgrade --canary

Jarred-Sumner avatar Sep 20 '22 03:09 Jarred-Sumner

@Jarred-Sumner Tried this on the latest (0.2.1) and it seems the issue is still there.

Any kind of flag needed, perhaps?

phaistonian avatar Oct 19 '22 06:10 phaistonian

@Jarred-Sumner Doesn't seem to work in 0.2.2.

vjpr avatar Nov 09 '22 09:11 vjpr

I couldn't get any #src/index.js imports to work.

error: Could not resolve: "#src/index.js". Maybe you need to "bun install"?

import index from '#src/index.js'
  "imports": {
    "#src/*": {
      "types": "./src/*.js",
      "transpile": "./src/*",
      "node": "./lib/*",
      "bun": "./src/*.js"
    }
  },
{
  "extends": "./node_modules/@live/scripts/tsconfig/tsconfig.json",
  "compilerOptions": {
    "rootDir": ".",
    "baseUrl": "src",
    "jsx": "react"
  }
}

But I also use wildcards which I found isn't supported yet https://github.com/oven-sh/bun/issues/1402 <- probably good to wait for this one.

Also found this ticket https://github.com/oven-sh/bun/issues/1337, that indicated bun subpath which is why I tried it above. Couldn't find docs on this.

vjpr avatar Nov 09 '22 15:11 vjpr

Canary just upgraded to 0.2.3 now...the command didn't upgrade earlier...rechecking.


EDIT: Everything I try doesn't seem to work still...

vjpr avatar Nov 09 '22 15:11 vjpr

I confirm that this is still an issue.

For example

import test from '#utils/test';

Will not work.

I guess that this has to do with extension resolution - e.g. test.js might work.

phaistonian avatar Oct 10 '23 10:10 phaistonian