Closed Cameron-C-Chapman closed 3 years ago
Thanks @Cameron-C-Chapman ... does your package.json has a main: app.js
property?
Thanks @Cameron-C-Chapman ... does your package.json has a
main: app.js
property?
Ok so judging by what you're saying the v2.0.3 update actually now checks your package.json for the main entry instead of what it did previously which was to force entry as app.js at the root directory, is this whats happened?
@freddieerg yep that's right
Thanks @Cameron-C-Chapman ... does your package.json has a
main: app.js
property?
I do have the main
property set to app.js
in my package.json. I have a build process that builds the app and places it in a dist
folder instead of the root folder.
Here is my input:src
setting in the serverelss.yml
file:
src:
src: ./
hook: npm run build
dist: ./dist/
The dist folder output just contains an app.js
and an app.js.map
file.
Should I tweak the package.json or the dist configuration at all?
@freddieerg yep that's right
Thank you! This was a much needed change IMO! :)
I'm using Nx.dev and so I only have one package.json at the top level of the project containing many apps and libraries. Any way I can fix this issue in another way?
EDIT:
I fixed this by using the generate-package-json-webpack-plugin to generate a single specific package.json in the dist
directory during the build.
@Cameron-C-Chapman how did you fix this? I'm trying to setup a new service using:
create --template-url https://github.com/serverless-components/express/tree/master/templates/express-starter-typescript-webpack --path service
I noticed the difference between the express-starter
template and the express-starter-typescript-tsc
and express-starter-typescript-webpack
was the latter didn't have the main: app.js
property in package.json @eahefnawy described.
I updated my package.json to have main: app.js
but still getting the same error you're getting:
` Error: Cannot find module '..' Require stack:
Anyways, any help on this would be great!
UPDATE
This fixed it:
https://github.com/serverless-components/express/issues/12#issuecomment-695839017
@albertocevallos I can't track down any change that would indicate this but for some reason the pre v2 version of this component seemed to honor a dist
directory but not the post v2.
I also can't find any evidence that the dist
configuration was ever explicitly accounted for, but the typescript template you are referring to has that set, and my current app that has the compiled app.js put in a dist folder and used that config worked before as well.
I have the main property set, it seems to just not be loading the app from the dist folder, but instead trying to load it from the src folder.
Again, this was working for me before with no changes on my end. My config is just like the comment you linked to, but using parcel instead of webpack.
I was thinking it might have to do with not looking in the configured dist folder and gave a fix a stab, #61, but maybe it has to do with node_modules no longer copying or being found like they were in a pre v2 version?
@Cameron-C-Chapman I'd suggest trying webpack instead, unless there's a specific reason to use Parcel (cache?).
And then using https://github.com/serverless-components/express/issues/12#issuecomment-695839017 and replacing dist
with build
.
@albertocevallos I finally got back to this and got it to work using the suggestions in this and the various linked threads 🎉
Thanks for helping me through that 😄
I'll go ahead and close this issue.
I wasn't specifying a version for the component in the serverless.yml file and when I deployed, I pulled in the latest version of the component and ran into the following error:
When I compared the 2 deployment packages (the last known working version and the latest that failed), I noticed the version difference and was able to resolve the issue by rolling back to 1.7.5 by specifying the version in my component property in the serverless.yml file.
The deployment packages look the same at a glance, and my application was bundled/packaged the same in both cases.
The @serverless/platform-client version went from 1.1.6 to 3.8.0 which was interesting but it's hard to tell exactly what is different between the 2 deployments.
I'm happy to provide more information, I'm just not sure what would be useful, but I wanted to report this as an issue.