Open stoivo opened 2 years ago
After some more hours of research, I have learned some more useful information.
The cause of the error was: I had left a package.json in the root in my docker container with type: module. When execjs created a tmp file(/tmp/........./execjs1312312js on linux and /var/folders/kt/... on macs) there package.json the root file was detected as closes parent package.json. It contain type: module. When I remove it all works fine.
From the error message below, I think node is requires users to spesicy cjs or mjs when type module is set in package.json
Error [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /tmp/execjs20220616-1662-1q9n3vujs. Loading extensionless files is not supported inside of "type":"module" package.json contexts. The package.json file /package.json caused this "type":"module" context. Try changing /tmp/execjs20220616-1662-1q9n3vujs to have a file extension. Note the "bin" field of package.json can point to a file with an extension, for example {"type":"module","bin":{"execjs20220616-1662-1q9n3vujs":"./tmp/execjs20220616-1662-1q9n3vujs.js"}}
I still think this is a good thing too add since this is common.js
If the nearest parent package.json lacks a "type" field, or contains "type": "commonjs", .js files are treated as CommonJS. If the volume root is reached and no package.json is found, .js files are treated as CommonJS. https://nodejs.org/api/packages.html#type
I changes my package.json(rails app), I added type: "module" and then assets:precompile stoped working.
I believe node works like if you try to run a .js file it will use the type in package.json. If you want to run a script with commonjs name it .cjs or as a module .mjs.
back in 2014 it seam like it did add the extension to the file
I don't know why it was removed.
https://github.com/sstephenson/execjs/pull/149
So I don't think it was on purpose. Also (I think) we didn't have js modules like we have them now so there where no reason to have the extension.
Maybe I should have created a minimal replication case but I didn't. It was just. Also I could not reproduce it on my mac but only on linux.