egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.48k stars 209 forks source link

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import #1042

Closed I-Want-ToBelieve closed 7 months ago

I-Want-ToBelieve commented 7 months ago
node:internal/process/esm_loader:108
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/i.want.to.believe/git.workspaces/js.workspaces/yakite/apps/yakite-bridge/node_modules/krohnkite-core/' is not supported resolving ES modules imported from /Users/i.want.to.believe/git.workspaces/js.workspaces/yakite/apps/yakite-bridge/dist/index.js
Did you mean to import krohnkite-core/dist/index.js?
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:320:17)
    at moduleResolve (node:internal/modules/esm/resolve:946:10)
    at defaultResolve (node:internal/modules/esm/resolve:1132:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///Users/i.want.to.believe/git.workspaces/js.workspaces/yakite/apps/yakite-bridge/node_modules/krohnkite-core/'
}

Node.js v20.9.0
{
    "compilerOptions": {
        // add Bun type definitions
        "types": [
            "bun-types"
        ],
        // enable latest features
        "lib": [
            "ESNext"
        ],
        "module": "esnext",
        "target": "esnext",
        // if TS 5.x+
        "moduleResolution": "bundler",
        "sourceMap": true,
        "noEmit": false,
        "allowImportingTsExtensions": false,
        "moduleDetection": "force",
        "resolveJsonModule": true,
        // if TS 4.x or earlier
        // "moduleResolution": "nodenext",
        // best practices
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "skipLibCheck": true,
        "composite": true,
        "downlevelIteration": true,
        "allowSyntheticDefaultImports": true,
    }
}
import { defineConfig } from 'tsup'
import { $ } from 'execa'

export default defineConfig({
  entry: ['src/bin/yakite-daemon.ts'],
  outDir: 'dist/bin',
  splitting: false,
  sourcemap: true,
  clean: true,
  format: 'esm',
  onSuccess: async () => {
    await $`tsc --emitDeclarationOnly --declaration`
    await $`tsc-alias`
  }
})

https://github.com/swc-project/swc/issues/7898

ocavue commented 7 months ago

@I-Want-ToBelieve Could you create a minimum reproduction? Thanks.

I-Want-ToBelieve commented 7 months ago

OMG, i found

// src/bridge.ts
import { EngineWindow, WindowState } from "krohnkite-core";
import Yabai from "yakite-yabai";

// src/window.ts
import { Rect as Rect2, matchWords } from "krohnkite-core/";

"krohnkite-core" work, but "krohnkite-core/" have a bug

I-Want-ToBelieve commented 7 months ago

delete it , work well image

I-Want-ToBelieve commented 7 months ago

image

I-Want-ToBelieve commented 7 months ago

Eslint and TypeScript and tsup don't report errors, but this slash is causing trouble for node's module parsing,

It's hard to say who is going to eradicate this problem, maybe I should avoid making this mistake

If you think this should be closed, then you can.