lucacasonato / esbuild_deno_loader

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

Error bundling script that uses @std/cli in Deno 2 :: https://jsr.io/@std/cli/1.0.6/_data.json:19:0: ERROR: JSON does not support comments #147

Closed allout58 closed 1 month ago

allout58 commented 1 month ago

When trying to use this builder as suggested by the official migration notes as a replacement for deno bundle, I get this strange error when trying to bundle my script using @std/cli:

X [ERROR] JSON does not support comments

    https://jsr.io/@std/cli/1.0.6/_data.json:19:0:
      19 │ // denoCacheMetadata={"headers":{"x-goog-hash":"crc32c=q17ozQ==,md5=yLD7K17e6pwkyJsJM9FaNA==","via":"1.1 google","accept-ranges":"bytes","x-goog-metageneration":"1","x-content-type-options":"nosniff","date":"Thu, 10 Oct 2024 21:15:10 GMT","last-modified":"Thu, 12 Sep 2024 10:26:29 GMT","expir...
         ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: Uncaught (in promise) Error: Build failed with 1 error:
https://jsr.io/@std/cli/1.0.6/_data.json:19:0: ERROR: JSON does not support comments
    at failureErrorWithLog (file:///C:/Users/jhollowell/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.24.0/lib/main.js:1476:15)
    at file:///C:/Users/jhollowell/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.24.0/lib/main.js:945:25
    at runOnEndCallbacks (file:///C:/Users/jhollowell/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.24.0/lib/main.js:1316:45)
    at buildResponseToResult (file:///C:/Users/jhollowell/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.24.0/lib/main.js:943:7)
    at file:///C:/Users/jhollowell/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.24.0/lib/main.js:970:16
    at responseCallbacks.<computed> (file:///C:/Users/jhollowell/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.24.0/lib/main.js:622:9)
    at handleIncomingPacket (file:///C:/Users/jhollowell/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.24.0/lib/main.js:677:12)
    at Readable.readFromStdout (file:///C:/Users/jhollowell/AppData/Local/deno/npm/registry.npmjs.org/esbuild/0.24.0/lib/main.js:600:7)
    at Readable.emit (ext:deno_node/_events.mjs:393:28)
    at addChunk (ext:deno_node/_stream.mjs:2438:16)

This file, when viewed on jsr.io in my browser, only has 17 lines and does not have the comment in the error message.

A minimal reproduction can be created with these two files: min.ts

import {parseArgs} from 'jsr:@std/cli@1.0.6';

parseArgs();
console.log('hi');

bundle.ts

import { denoPlugins } from 'jsr:@luca/esbuild-deno-loader';
import * as esbuild from 'npm:esbuild';

const result = await esbuild.build({
    plugins: [...denoPlugins()],
    entryPoints: ['./min.ts'],
    outfile: './dist/min.esm.js',
    bundle: true,
    format: 'esm',
});

await esbuild.stop();

Running deno run --allow-all bundle.ts errors out. Using

deno 2.0.0 (stable, release, x86_64-pc-windows-msvc)
v8 12.9.202.13-rusty
typescript 5.6.2

We went back and checked and are able to use the same script and bundler in deno 1.4.6

marvinhagemeister commented 1 month ago

Resolved by https://github.com/lucacasonato/esbuild_deno_loader/pull/141