Skip to content

Generated code requires modules from bs-platform, forcing an extra production dependancy #2082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lpil opened this issue Sep 30, 2017 · 7 comments

Comments

@lpil
Copy link

lpil commented Sep 30, 2017

Hello!

My compiled bucklescript code imports modules from bs-platform such as bs-platform/lib/js/pervasives.js. I'm not using a module bundler (making a node application), so I need to have these modules present on my production server.

I don't wish to add bs-platform to my production deps because it's ~220MB and runs some postinstall scripts. I'm targeting GCP's FaaS so I'm unable to manually add these files to my production node_modules.

Currently I'm looking to manually copy these bs-platform files to my output directory and run a regex on this directory to modify the require paths, which is quite fiddly.

For people like me writing node applications I think it would be nice to set a flag and have bsb write all the required Javascript modules (i.e. bs-platform/lib/js/pervasives.js) to the output directory and then use relative require paths.

Thanks,
Louis

@bobzhang
Copy link
Member

bobzhang commented Oct 2, 2017

@lpil do you run npm on GCP? If not, can you run a script remove all those binary files which is not needed for production

@lpil
Copy link
Author

lpil commented Oct 2, 2017

npm install is run by the platform rather than by a script written by me. This is also the case for other platform-as-a-services.

Removing the binaries after the fact is possible but less ideal as I'll need to install them in the first place, which is slow and means I have to ensure the postinstall script runs in an excitment that is outside of my control.

It'd be really great if the output directory could be copy-pasted to anywhere and feel confident that it will run so long as there is a working Node JS installation :)

Thanks

@arnihermann
Copy link

We're writing code in reason and deploying it to Google's Cloud Function platform (more specifically Firebase Cloud Functions). We ended up using rollup for bundling and moved bs-* deps to devDependencies which makes it a part of our build step before deployment to perform bundling. This works well in practice since cloud functions only installs dependencies listed underdepdendencies, not devDependencies in package.json.

@bassjacob
Copy link
Contributor

@arnihermann this is what I've done in the past with aws-lambda

@lpil
Copy link
Author

lpil commented Oct 3, 2017

Is there a way to do this while preserving stack traces so that it lists the original file location rather than somewhere in one large file?

@bassjacob
Copy link
Contributor

I don't know of one for node. But rather than bundling, you could always just zip up what you want to send on CI and use that as the deployable artefact (including node_modules).

@bobzhang
Copy link
Member

closed as a duplication of #2127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants