milesj/packemon

Bug: `native` platform exports are pointing to the incorrect files when also building `node`

j3tan opened this issue · 5 comments

j3tan commented

version: 3.x

Test Repo: https://github.com/j3tan/packemon-native-web-package

native exports look like:

{
  "exports": {
    "./mobile": {
      "react-native": {
        "types": "./lib/native/mobile/index.d.ts", <==== This is incorrect
        "default": "./lib/native/mobile.js" <==== This is incorrect
      },
      "default": "./lib/native/mobile.js" <==== This is incorrect
    },
  }
 }

but the file structure looks like:

lib/
├── mobile/
│   ├── mobile.js
│   ├── mobile.js.map
├── native/
│   ├── index.d.ts
│   ├── index.d.ts.map
{
  "packemon": [
    { <== Removing this target fixes the issue
      "bundle": true,
      "format": "lib",
      "platform": "node"
    },
    {
      "bundle": true,
      "format": "esm",
      "platform": "browser",
      "inputs": {
        "web": "src/web/index.ts"
      }
    },
    {
      "bundle": true,
      "format": "lib",
      "platform": "native",
      "inputs": {
        "mobile": "src/mobile/index.ts"
      }
    }
  ]
 }

My guess is a conflict when building 2 format lib targets?

j3tan commented

I can confirm that using native platform without subpaths works fine.

@j3tan So I can't reproduce this: #189

The fs output I see locally is exactly what I expect it to be and does not look like yours. I did notice an issue with type paths but that wouldn't cause what you're seeing.

I think the issue is that there is no fallback "types" field exported, so if a package is being built for npm publishing, the types
for an import to the /types path will not be found. Once that "default"/fallback "types" field was added in I was able to build successfully
I created a PR with a fix: #194

So the previous issue I created the PR for seems to actually be a separate issue, but for the specific issue @j3tan is describing, I think this would be the/a fix: #195

j3tan commented

fixed in #194