emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.72k stars 3.3k forks source link

emconfigure fails inside "type": "module" package #13551

Open aduh95 opened 3 years ago

aduh95 commented 3 years ago

Repro:

$ echo '{"type":"module"}' > package.json
$ curl -L https://github.com/libexpat/libexpat/releases/download/R_2_2_10/expat-2.2.10.tar.xz | tar -xJ
$ cd expat-2.2.10
$ emconfigure ./configure
configure: ./configure
checking build system type... x86_64-apple-darwin20.3.0
checking host system type... x86_64-apple-darwin20.3.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... conftools/install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... …/emsdk/upstream/emscripten/emcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in `…/expat-2.2.10':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details

And in config.log:

configure:3744: checking whether we are cross compiling
configure:3752: …/emsdk/upstream/emscripten/emcc -o conftest    conftest.c  >&5
configure:3756: $? = 0
configure:3763: ./conftest
(node:90074) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:54
    internalBinding('errors').triggerUncaughtException(
                              ^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for …/expat-2.2.10/conftest
    at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
    at Loader.getFormat (internal/modules/esm/loader.js:113:42)
    at Loader.getModuleJob (internal/modules/esm/loader.js:244:31)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Loader.import (internal/modules/esm/loader.js:178:17) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
configure:3767: $? = 1
configure:3774: error: in `…/expat-2.2.10':
configure:3776: error: cannot run C compiled programs.

This could be solved if emconfigure added a package.json file in the current directory:

{ "type" : "commonjs" }
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

shamrin commented 2 years ago

@aduh95 I've stumbled upon a similar problem in #17431. Library is different, symptoms are different. But the underlying cause and the exception in config.log are the same.

sbc100 commented 2 years ago

I see, it looks like the "#!" line that runs the emscripten "executables" under node is effected by package.json files. I guess we could/should override that in the #!?

dsogari commented 8 months ago

Please see my https://github.com/emscripten-core/emscripten/pull/17451#issuecomment-1902274071 for a possible fix.