Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object with shim targets in the short-hand format result in invalid compilation #329

Open
a-miyashita opened this issue Aug 7, 2023 · 0 comments

Comments

@a-miyashita
Copy link

Description

When compiling a following program that supports ES module, an invalid objects is generated.

To reproduce

  1. Create src/tests.ts and scripts/build_npm.ts.

src/test.ts

export const _internals = {
  prompt,
};

scripts/build_npm.ts

import { build } from "https://deno.land/x/dnt/mod.ts";

await build({
  typeCheck: false,
  scriptModule: false,
  skipSourceOutput: true,
  entryPoints: [ `src/test.ts` ],
  outDir: "./dist",
  shims: {
     prompts: true,
  },
  package: { 
    name: "package_name",
    version: Deno.args[0],
  },
});
  1. Run the following command to build the npm package:

    $ deno run -A scripts/build_npm.ts 0.1.0
    

Expected

dist/esm/test.js

export const _internals = {
    prompt: dntShim.prompt,
};

Actual

Build failed with following code and an error.

dist/esm/test.js

export const _internals = {
    dntShim, : .prompt,
};

Error message

[dnt] Transforming...
[dnt] Running npm install...

added 1 package, and audited 3 packages in 2s

found 0 vulnerabilities
[dnt] Building project...
[dnt] Emitting ESM package...
[dnt] Running tests...

> package_name@0.1.0 test
> node test_runner.js


Running tests in ./esm/test.js...

file:///tmp/tmp.j8gohGBMqN/dist/esm/test.js:3
    dntShim, : .prompt,
             ^

SyntaxError: Unexpected token ':'
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:468:14)
    at async link (node:internal/modules/esm/module_job:68:21)

Node.js v18.14.2
error: Uncaught (in promise) Error: npm run test failed with exit code 1
      throw new Error(
            ^
    at runCommand (https://deno.land/x/dnt@0.38.0/lib/utils.ts:56:13)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async build (https://deno.land/x/dnt@0.38.0/mod.ts:407:5)
    at async file:///tmp/tmp.j8gohGBMqN/scripts/build_npm.ts:3:1

Workaround

There is a workaround for this problem. It is to not use the short-hand format.

src/test.ts

export const _internals = {
  prompt: prompt,
};

will result in expected output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant