denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.22k stars 5.37k forks source link

Bug: `exports` is `undefined` in NestJS #25454

Open marvinhagemeister opened 1 month ago

marvinhagemeister commented 1 month ago

Reported on discord: https://discord.com/channels/684898665143206084/1281161740138319872/1281161740138319872

$ deno run -A main.js
error: Uncaught (in promise) ReferenceError: exports is not defined
Object.defineProperty(exports, "__esModule", { value: true });
                      ^
    at file:///home/sheik/Documentos/project-name/dist/main.js:2:23

Version: Deno 1.46.3

rroblf01 commented 1 month ago

To add information

The main.js is the result of building a newly created NestJS project.

Steps to follow to reproduce it

nest new project-name
cd project-name
npm run build
deno run -A dist/main.js
bartlomieju commented 1 month ago

There's now a workaround for this problem with https://github.com/denoland/deno/pull/25426 landed.

Upgrade to latest canary (deno upgrade --canary), rename dist/main.js to dist/main.cjs, run with deno run -A dist/main.cjs.

This suggestion will be printed once https://github.com/denoland/deno/pull/21764 lands.

rroblf01 commented 1 month ago

@bartlomieju Ohh, with those changes it works. Will it be necessary to rename it to .cjs in the future?

bartlomieju commented 1 month ago

@bartlomieju Ohh, with those changes it works. Will it be necessary to rename it to .cjs in the future?

For now we don't have any plans to sniff out module type based on package.json, so I'd say yes.