https://serverless-stack.com/ logo
#help
Title
# help
s

Sulaiman Baig

03/10/2022, 12:32 PM
In dev mode, everything is working fine but in production mode, it is throwing an error I showed in the image. How and where to install mysql2. Can any senior guide me?
r

Ross Coundon

03/10/2022, 12:34 PM
Is MySql2 in your dependencies? If so, you might need to add it to bundle.nodeModules
s

Sulaiman Baig

03/10/2022, 12:41 PM
@Ross Coundon It is already in dependencies and it is working in dev mode. What else to do further?
r

Ross Coundon

03/10/2022, 12:42 PM
Can you try adding to bundle.nodeModules?
s

Sulaiman Baig

03/10/2022, 12:44 PM
@Ross Coundon I don't know where is bundle.nodeModules. Please mention it
r

Ross Coundon

03/10/2022, 12:49 PM
You can set the bundle property on the function that uses it by setting it in the functionProps. Or you can set it for all using defaultFunctionProps at the app level like
Copy code
app.setDefaultFunctionProps({
  bundle: {
    nodeModules: ['mysql2']
  }
});
Docs are here.
s

Sulaiman Baig

03/10/2022, 12:58 PM
This time I got this error app.setDefaultFunctionProps({ runtime: "nodejs14.x", timeout: 20, bundle: { nodeModules: ['mysql2'] } });
r

Ross Coundon

03/10/2022, 1:00 PM
Ok, no idea what that is. I’d be inclined to delete the .sst directory and re-run at this point
s

Sulaiman Baig

03/10/2022, 1:08 PM
I dropped .sst and build it again. It is throwing as follows Preparing your SST app Synthesizing CDK Building function src/lambda.handler There was a problem installing nodeModules. Error: Command failed: npm install npm WARN dev-condofamily-api-Api-Lambda_GET_- No description npm WARN dev-condofamily-api-Api-Lambda_GET_- No repository field. npm WARN dev-condofamily-api-Api-Lambda_GET_- No license field.
app.setDefaultFunctionProps({ runtime: "nodejs14.x", timeout: 20, // bundle: { // nodeModules: ['mysql2'] // } }); I commented bundleModule then got no error
r

Ross Coundon

03/10/2022, 1:16 PM
Ok, it seems there’s something odd about how the mysql2 is being handled. Specifying it in the nodeModules array prevents SST bundling it and instead just installs it into node_modules. The fact that it breaks when you do that is really weird. Probably one for @thdxr when he wakes up
s

Sulaiman Baig

03/10/2022, 1:23 PM
@Ross Coundon I appreciate your quick response and support. Thanks from the core of my heart.
@thdxr seeking guidance from you in this regard.
r

Ross Coundon

03/10/2022, 1:28 PM
Which version of sst are you using?
I’ve added mysql2 to the bundle.nodeModules of an app I’m working on to see what would happen and it seems to work fine
so maybe something specific to your machine
I’m using a Mac in case that’s a factor
t

thdxr

03/10/2022, 1:32 PM
Hm I use mysql2 in this way
You do need to add it to bundle like Ross mentioned
But idk what the error you're seeing is
s

Sulaiman Baig

03/10/2022, 2:12 PM
@Ross Coundon "version": "0.1.0",
r

Ross Coundon

03/10/2022, 2:13 PM
SST?
s

Sulaiman Baig

03/10/2022, 2:16 PM
@thdxr
t

thdxr

03/10/2022, 2:16 PM
yeah this is some weird npm issue I'm not sure. You've tried deleting .sst folder and node_modules?
s

Sulaiman Baig

03/10/2022, 2:17 PM
@Ross Coundon
@thdxr I tried deleting .sst not node modules. Now I am deleting both then will see
@thdxr Also need to delete .build or not?
r

Ross Coundon

03/10/2022, 2:24 PM
Won’t hurt
s

Sulaiman Baig

03/10/2022, 2:24 PM
ok
.sst and node modules deleted and could not run npm install
r

Ross Coundon

03/10/2022, 2:40 PM
I think you have some kind of user access privileges issue on the file system
s

Sulaiman Baig

03/10/2022, 3:07 PM
@Ross Coundon I have admin privileges. I deleted package-lock.json now node modules installed. Let me check bundle.nodeModule works now or not
@Ross Coundon @thdxr After deleting .sst and node modules and after reinstalling it is working fine. All issues resolved. Thanks for helping alot
r

Ross Coundon

03/10/2022, 3:32 PM
Gotta love those 😬
10 Views