lucacasonato / esbuild_deno_loader

Deno module resolution for `esbuild`
https://jsr.io/@luca/esbuild-deno-loader
MIT License
176 stars 46 forks source link

npm specifiers with subdirectories fail to create destination directory #72

Closed Ciantic closed 1 year ago

Ciantic commented 1 year ago

The gist of the issue is this:

X [ERROR] The system cannot find the path specified. (os error 3): rename 'C:\...\Temp\9ead501e' -> '...\deno_esbuild\@tanstack\table-core@8.8.4\node_modules\@tanstack\table-core' [plugin deno-loader]

deno-loader is trying to rename directory without creating the destination first.

If I manually make this destination directory:

C:\Users\jarip\AppData\Local\deno\deno_esbuild\@tanstack\table-core@8.8.4\node_modules\@tanstack\table-core

Then it resumes.

More error details

C:\Source\Deno\denotest>deno run -A bundle.ts
X [ERROR] The system cannot find the path specified. (os error 3): rename 'C:\Users\jarip\AppData\Local\Temp\9ead501e' -> 'C:\Users\jarip\AppData\Local\deno\deno_esbuild\@tanstack\table-core@8.8.4\node_modules\@tanstack\table-core' [plugin deno-loader]

    ../../../Users/jarip/AppData/Local/deno/deno_esbuild/@tanstack/solid-table@8.8.4_solid-js@1.6.15/node_modules/@tanstack/solid-table/build/lib/index.mjs:11:28:
      11 │ import { createTable } from '@tanstack/table-core';
         ╵                             ~~~~~~~~~~~~~~~~~~~~~~

error: Uncaught Error: Build failed with 1 error:
../../../Users/jarip/AppData/Local/deno/deno_esbuild/@tanstack/solid-table@8.8.4_solid-js@1.6.15/node_modules/@tanstack/solid-table/build/lib/index.mjs:11:28: ERROR: [plugin: deno-loader] The system cannot find the path specified. (os error 3): rename 'C:\Users\jarip\AppData\Local\Temp\9ead501e' -> 'C:\Users\jarip\AppData\Local\deno\deno_esbuild\@tanstack\table-core@8.8.4\node_modules\@tanstack\table-core'
    at failureErrorWithLog (file:///C:/Users/jarip/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.17.10/lib/main.js:1636:15)
    at file:///C:/Users/jarip/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.17.10/lib/main.js:1048:25
    at runOnEndCallbacks (file:///C:/Users/jarip/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.17.10/lib/main.js:1471:45)
    at buildResponseToResult (file:///C:/Users/jarip/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.17.10/lib/main.js:1046:7)
    at file:///C:/Users/jarip/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.17.10/lib/main.js:1075:16
    at responseCallbacks.<computed> (file:///C:/Users/jarip/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.17.10/lib/main.js:697:9)
    at handleIncomingPacket (file:///C:/Users/jarip/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.17.10/lib/main.js:752:9)
    at Readable.readFromStdout (file:///C:/Users/jarip/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.17.10/lib/main.js:673:7)
    at Readable.emit (ext:deno_node/_stream.mjs:1852:9)
    at addChunk (ext:deno_node/_stream.mjs:2874:16)

Reproduce

bundle.ts

import * as esbuild from "npm:esbuild";
import { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.1/mod.ts";

await esbuild.build({
    plugins: [...denoPlugins({
        loader: "native"
    })],
    entryPoints: ["test.ts"],
    outfile: "test.js",
    bundle: true,
    format: "esm",
});

test.ts

import {
    flexRender
} from "npm:@tanstack/solid-table";

export function test() {
    flexRender(null, {});
}

Then run deno run -A bundle.ts

Ciantic commented 1 year ago

I think the problem is here:

https://github.com/lucacasonato/esbuild_deno_loader/blob/be487a9ff71f52c27c92366426e9c351d47715b1/src/loader_native.ts#L105-L110

And here:

https://github.com/lucacasonato/esbuild_deno_loader/blob/be487a9ff71f52c27c92366426e9c351d47715b1/src/loader_native.ts#L128-L129

Since the linkDirParent isn't necessarily just one "/" slash behind it actually doesn't work. I will try to experiment with modifying those lines.

Imagine if you have a module that has slashes like @tanstack/solid-table it just creates the "node_modules" but not the @tanstack, thus the rename fails.

Ciantic commented 1 year ago

I've tested the same issue happens in Linux:

jarppa@Jari-Ryzen:~/projects/denotest$ deno run -A bundle.ts
✘ [ERROR] No such file or directory (os error 2): rename '/tmp/8887c786' -> '/home/jarppa/.cache/deno/deno_esbuild/@tanstack/solid-table@8.9.2_solid-js@1.7.6/node_modules/@tanstack/solid-table' [plugin deno-loader]

    test.ts:3:7:
      3 │ } from "npm:@tanstack/solid-table";
        ╵        ~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: Uncaught Error: Build failed with 1 error:
test.ts:3:7: ERROR: [plugin: deno-loader] No such file or directory (os error 2): rename '/tmp/8887c786' -> '/home/jarppa/.cache/deno/deno_esbuild/@tanstack/solid-table@8.9.2_solid-js@1.7.6/node_modules/@tanstack/solid-table'
    at failureErrorWithLog (file:///home/jarppa/.cache/deno/npm/registry.npmjs.org/esbuild/0.18.3/lib/main.js:1636:15)
    at file:///home/jarppa/.cache/deno/npm/registry.npmjs.org/esbuild/0.18.3/lib/main.js:1048:25
    at runOnEndCallbacks (file:///home/jarppa/.cache/deno/npm/registry.npmjs.org/esbuild/0.18.3/lib/main.js:1471:45)
    at buildResponseToResult (file:///home/jarppa/.cache/deno/npm/registry.npmjs.org/esbuild/0.18.3/lib/main.js:1046:7)
    at file:///home/jarppa/.cache/deno/npm/registry.npmjs.org/esbuild/0.18.3/lib/main.js:1075:16
    at responseCallbacks.<computed> (file:///home/jarppa/.cache/deno/npm/registry.npmjs.org/esbuild/0.18.3/lib/main.js:697:9)
    at handleIncomingPacket (file:///home/jarppa/.cache/deno/npm/registry.npmjs.org/esbuild/0.18.3/lib/main.js:752:9)
    at Readable.readFromStdout (file:///home/jarppa/.cache/deno/npm/registry.npmjs.org/esbuild/0.18.3/lib/main.js:673:7)    at Readable.emit (ext:deno_node/_stream.mjs:1852:9)
    at addChunk (ext:deno_node/_stream.mjs:2874:16)
Ciantic commented 1 year ago

I made a pull request #73 to fix this, if someone else is blocked by this bug you can use my branch like this until this is fixed:

import { denoPlugins } from "https://cdn.jsdelivr.net/gh/Ciantic/esbuild_deno_loader/mod.ts";

Via jsdelivr.net

lucacasonato commented 1 year ago

Fixed by #80