bytenode: Dependency resolving problem with compiled byte code

Hi, I tried the library with an app developed using the Nest.JS framework. Library converted the bundle.js into bytecode and code ran without any errors. NOTE: bundle.js was built following the bellow step 2.

However, I wanted to try with more advanced cases such as connecting to a database.

  1. I did setup the application to use sqlite3 along with TypeORM.

  2. Compiled the application into a single bundle using ncc library, NTOE: ncc library also copied the sqlite3 related node native module to the build folder successfully.

Now the library can run as a standalone file and tested and confirmed that I can do CURD operations with the database.

  1. After the successful test confirm I compiled the bundle.js with the bytenode and it could generate a compiled bytecode file.

When I run the code using bytenode ./build/bundle.jsc it throws the error of not resolving the ORM Repository.

I could not find any resources/ configurations to solve this issue. Please help.

Resources: @nestjs/core: ^8.0.0 sqlite3: ^5.0.2 typeorm: ^0.2.37 @vercel/ncc: ^0.31.1 bytenode: ^1.3.3 typescript: ^4.3.5

Thank you very much

About this issue

Most upvoted comments

I can reproduce your error now. However, I don’t even know how to approach the problem! There are many parts, each could potentially be the cause, and I have almost no experience with them.

I tried to google the error message. There are many people who had the same error but without bytenode. It was all related to nest configurations.

I believe that the way bytenode is wrapping your code inside this function (function (exports, require, module, __filename, __dirname) { YOUR_CODE \n}); plays a role. Maybe it causes some implicit globals to be lost. Maybe you should explicitly export what the error message is complaining about.

I’m sorry I could not help.

@AwesomeSam9523 Hi, No worries, I will try what you are suggesting here, But it was good to know this as well. Thank you very much for the info anyway. I am trying to run the code in NWJS 😃 Thank you very much once again

@ishanuda

require('bytenode');
module.exports = require('./filename.jsc');

Hi, I will try to debug further and get back here soon with findings. Thank you very much for your support and information

Hi, Sorry for my bad, There should be an env file that I ignored in the commit. I have updated the env file so that the validation will pass while running.

NOTE: The .env file is mounted in app.module.ts with the following code.

envFilePath: path.resolve(__dirname, '../env', '.env'),

Thank you

Thank you for creating the minimal example. I apologize for the late response, and I will look into it in the weekend.

Hi @OsamaAbbas, Thank you for the reply. I ran the suggested command and it still fails the operation. However, I created a minimal repo in the following:

https://github.com/ishanuda/nestjs-ncc-bytenode

NOTE: I have update the README for your reference.

Thank you very much.

Could you please provide a complete minimal example that shows the problem with a simple npm install && npm run?

Also, try running the project like this: node -r bytenode ./build/bundle.jsc.