In dev mode, everything is working fine but in pro...
# help
s
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
Is MySql2 in your dependencies? If so, you might need to add it to bundle.nodeModules
s
@Ross Coundon It is already in dependencies and it is working in dev mode. What else to do further?
r
Can you try adding to bundle.nodeModules?
s
@Ross Coundon I don't know where is bundle.nodeModules. Please mention it
r
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
This time I got this error app.setDefaultFunctionProps({ runtime: "nodejs14.x", timeout: 20, bundle: { nodeModules: ['mysql2'] } });
r
Ok, no idea what that is. I’d be inclined to delete the .sst directory and re-run at this point
s
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
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
@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
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
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
@Ross Coundon "version": "0.1.0",
r
SST?
s
@thdxr
t
yeah this is some weird npm issue I'm not sure. You've tried deleting .sst folder and node_modules?
s
@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
Won’t hurt
s
ok
.sst and node modules deleted and could not run npm install
r
I think you have some kind of user access privileges issue on the file system
s
@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
Gotta love those 😬