PleaseUpgradeNode issues with NCC/Webpack
Description
When building a bolt app with ncc (which uses webpack) pleaseUpgradeNode in the index breaks as it can't find your package.json. I have a monorepo and it picked up my root package.json (which didn't have engines in it).
Error:
/dist/webpack:/node_modules/please-upgrade-node/index.js:5
var requiredVersion = pkg.engines.node.replace('>=', '')
^
TypeError: Cannot read property 'replace' of undefined
at pleaseUpgradeNode (/dist/webpack:/node_modules/please-upgrade-node/index.js:5:1)
at Object.36141 (/dist/webpack:/node_modules/@slack/bolt/dist/index.js:20:1)
Possible solutions:
It strikes me that please-upgrade-node is designed for CLI tools, not libraries. Simply embedding the engine config into the index would work great, It does introduce some duplication though. You distribute your own webpack'd version of the library, maybe you can build it in? Lots of good solutions out there.
After combing through the generated files I found a workaround for me that I just need to add an engines.node block into my own package, but that wasn't the intentions of the bolt authors I assume.
What type of issue is this? (place an x in one of the [ ])
- [x] bug
- [ ] enhancement (feature request)
- [ ] question
- [ ] documentation related
- [ ] example code related
- [ ] testing related
- [ ] discussion
Requirements (place an x in each of the [ ])
- [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
- [x] I've read and agree to the Code of Conduct.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
NA
Steps to reproduce:
- Take an example bolt app,
- build it with
nccintodist(something likencc build src/index.ts -o dist) -
node dist/index.js - See error above
Expected result:
The app should run as normal
Actual result:
The error at the top
Attachments:
Logs, screenshots, screencast, sample project, funny gif, etc.
Hey @barlock thanks for writing in.
I can't reproduce with the repro steps you provided:
13:56:00 in ~/src/plzupgradenodeslapp is 📦 v1.0.0
➜ cat src/app.js
const { App } = require('@slack/bolt');
// Initializes your app with your bot token and signing secret
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
});
(async () => {
// Start your app
await app.start(process.env.PORT || 3000);
console.log('⚡️ Bolt app is running!');
})();
13:56:08 in ~/src/plzupgradenodeslapp is 📦 v1.0.0
➜ ncc build src/app.js -o dist
ncc: Version 0.33.1
ncc: Compiling file index.js into CJS
1718kB dist/index.js
1718kB [2479ms] - ncc 0.33.1
13:56:15 in ~/src/plzupgradenodeslapp is 📦 v1.0.0 took 2s
➜ node dist/index.js
⚡️ Bolt app is running!
I also tried removing the package.json from the root of my app but the app still works fine.
Any tips on how best I can reproduce the issue?
I made a repo to reproduce: https://github.com/barlock/bolt-issue-repro
After cloning:
- Install deps:
yarn install - use
nccto compile:yarn build - start the built app and get error:
yarn start
I'm honestly not sure what the difference is between your steps and mine. I thought it might be typescript, but that doesn't appear to be it. I'll be curious if you can reproduce with my repo.
Thanks, indeed I can repro now.
Looks like the project's package json gets copied and injected into the bundle generated by ncc.
I'm not sure duplicating the engines content into the index is a nice change 😞 . We don't actually use webpack to build and distribute this library, only tsc, so I don't think building with webpack is a viable approach either. Both feel like workarounds for how bundlers mess with this project's code in non-standard ways.
I'm open to solving this issue but also don't want to bend over backwards just to appease whatever new bundler's non-standard module resolution approach happens to come along. If you have suggestions, we're open to ideas!