Skip to content
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

Using built-in node modules #29

Closed
yahiaboudah opened this issue May 29, 2022 · 6 comments
Closed

Using built-in node modules #29

yahiaboudah opened this issue May 29, 2022 · 6 comments

Comments

@yahiaboudah
Copy link

I tried everything, I put it in installModules in the config, I tried require, I tried import, I tried using plugins, I tried using everything, it's just not working, please help I'm on a deadline

@yahiaboudah
Copy link
Author

I even put it in the html, how do I integrate this child process thing?

@yahiaboudah yahiaboudah changed the title [URGENT] I can't use child_process in my app dammit May 30, 2022
@justintaylor-dev
Copy link
Contributor

For anyone else who finds this thread, child_process is a built-in node module so it doesn't require bundling.

In Bolt, you can import with import { child_process } from "../lib/node";

@yahiaboudah
Copy link
Author

Wait, I tried doing that and it's giving me this error:

src/js/lib/node.ts:15:20 - error TS2307: Cannot find module 'child_process' or its corresponding type declarations.

15 ) as typeof import("child_process");

@yahiaboudah yahiaboudah changed the title dammit Using built-in node modules May 30, 2022
@yahiaboudah
Copy link
Author

For the now the error went away, and I am getting a proper build by adding nodeTypes to vite config in (resolve/alias):
{ find: '@nodeTypes', replacement: path.resolve(__dirname, 'node_modules/@types/node') }
and replacing child_process with "@nodeTypes/child_process".

However I will have to use some kind of placeholder to run in the web since the node stuff only runs within Adobe.

Anyway, thanks for the help

@justintaylor-dev
Copy link
Contributor

Are you running Node.js 16 or up? The /lib/node.ts file already does that by returning a blank object if you're in the browser or the node module if you're in a node environment.

@yahiaboudah
Copy link
Author

Node version: v16.13.1

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

No branches or pull requests

2 participants