Open selfagency opened 2 years ago
Did you find any alternatives? I just wasted 3 hours on this and came to the same conclusion
@174n esbuild was the only thing i could get working without tearing my hair out
I tried to waste 3 days, and I was able to make it working by using rollup
before ncc
I bumped into the very same issue with ncc
outputting eval('require')
. I discovered that it happens when ncc
is not able to find a package in the node_modules
folder. In my case one of the npm
packages I was using had a dependency on a node-fetch v2.6.7
package, which in turn has encoding
package as a peerDependency
.
I kept getting that error until I manually installed that peerDependency
as a dependency
into the project.
🧐 To sum up: when ncc
is not able to find the package, it outputs eval('require')('<package_name>')
. When it is able to find the package, it correctly outputs __WEBPACK_EXTERNAL_createRequire(import.meta.url)('<package_name>')
.
For anyone stumbling in to similar issues where eval('require)('src/main')
when trying to use "type": "module"
for their GitHub actions otherwise it won't compile properly and you have no code in your dist/index.js
You need to use full relative path like so:
import {run} from './src/main.js'
await run()
See https://github.com/updatecli/updatecli-action/pull/100 for a complete ESM github action :)
lmao
go with esm modules and use
import
statements and ncc generates esm code witheval('require')
so node throwsrequire is not defined in ES module scope
.drop esm modules and use
require
statements and ncc compiles cjs code (even with--target es2015
specified) and node throwsError: Cannot find module
for each required local module because when you userequire
it doesn't bundle local modules(???).i just wasted hours of my life trying to figure out what i'm doing wrong only to realize what i'm doing wrong is trying to use ncc in the first place, apparently. i can't believe github recommends this officially in their documentation.