denoland / deno

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

Bug: deno compile fails with npm:ali-oss package due to module resolution error (v2.1.0) #26961

Closed iugo closed 16 hours ago

iugo commented 1 day ago

Version: Deno 2.1.0

Title: [Bug] deno compile fails with npm:ali-oss package due to module resolution error

Description

When trying to compile a Deno project that imports the npm:ali-oss package using deno compile, the compilation fails with a module resolution error.

Reproduction Steps

  1. Create a file deno210.ts with the following content:
import oss from 'npm:ali-oss@6.20.0';
import type { STS as STS } from 'npm:@types/ali-oss@6.16.11';
console.log(oss);
  1. Run the compile command:
deno compile -A --output=dist deno210.ts
  1. Run the compiled binary with:
./dist

Current Behavior

The compilation fails with the following error:

error: Uncaught (in promise) Error: [ERR_MODULE_NOT_FOUND] Cannot find module 'file:///var/folders/8c/y14m5fh554dbyv6w8xng7kb00000gn/T/deno-compile-dist/.deno_compile_node_modules/localhost/ali-oss/6.20.0/lib/common/utils/isObject' imported from 'file:///var/folders/8c/y14m5fh554dbyv6w8xng7kb00000gn/T/deno-compile-dist/.deno_compile_node_modules/localhost/ali-oss/6.20.0/lib/common/utils/lowercaseKeyHeader.ts'
    at loadESMFromCJS (node:module:761:21)
    at Module._compile (node:module:729:14)
    at Object.Module._extensions..js.Module._extensions..ts.Module._extensions..jsx.Module._extensions..tsx (node:module:754:10)
    at Module.load (node:module:662:32)
    at Function.Module._load (node:module:534:12)
    at Module.require (node:module:681:19)
    at require (node:module:797:16)
    at Object.<anonymous> (file:///var/folders/8c/y14m5fh554dbyv6w8xng7kb00000gn/T/deno-compile-dist/.deno_compile_node_modules/localhost/ali-oss/6.20.0/lib/common/signUtils.js:4:32)
    at Object.<anonymous> (file:///var/folders/8c/y14m5fh554dbyv6w8xng7kb00000gn/T/deno-compile-dist/.deno_compile_node_modules/localhost/ali-oss/6.20.0/lib/common/signUtils.js:357:4)
    at Module._compile (node:module:745:34)

Expected Behavior

The compilation should succeed and generate a standalone executable that can use the ali-oss package.

Environment

Additional Context

This seems to be related to how Deno handles npm package compilation, specifically with packages that have internal CommonJS/ESM dependencies. The ali-oss package appears to have some internal module resolution issues when being compiled with deno compile.

Important: The same code compiles and runs successfully with Deno 2.0.6, indicating this might be a regression introduced in a more recent version.

nathanwhit commented 16 hours ago

Should be fixed in 2.1.1 (it no longer reproduces for me locally after updating), but feel free to reopen if you're still encountering issues on 2.1.1.