Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

would be cool to see a lerna + typescript + serverless-webpack example #50

Closed
derek-lewis opened this issue Mar 8, 2021 · 7 comments
Closed

Comments

@derek-lewis
Copy link

Would be great to see an example of:

/example

  • /core (@exmaple/core - a shared lib)
    --/lib/test.ts
  • /services
    --/serverless-api (AWS API Gateway)
    --- depends on @example/core
@derek-lewis
Copy link
Author

I have an example working. However, I am seeing an error on the @example/lib dependancy...

offline: Failure: Module parse failed: The keyword 'interface' is reserved (11:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

@NiGhTTraX
Copy link
Owner

I haven't used serverless-webpack, but would the example be different from the included webpack example?

offline: Failure: Module parse failed: The keyword 'interface' is reserved (11:0)

Usually this means your loaders are not set up to compile code outside the current module. Notice how the loader in the example doesn't have an include config that would limit the compilation scope. The CRA example is similar.

@florianbepunkt
Copy link

I'm on the same path, trying to use a monorepo with typescript and serverless webpack. This basically works with the webpack example. But in most serverless projects I did, sooner or later I encountered some webpack-incompatible modules. But if you want to exclude some webpack-incompatible packages, the example does not work any more.

If you exclude them in webpack.config.js with nodeExternals like so

externals: [
    nodeExternals({}),
    nodeExternals({
      modulesDir: path.resolve(__dirname, "../../node_modules"),
    }),
  ]

you'll get a runtime error


{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module '@nighttrax/bar'\nRequire stack:\n- /var/task/src/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    // stack omitted for brevity
}

After this I tried to set the node_modules path to the root in the serverless webpack config:

custom:
  webpack:
    webpackConfig: "./webpack.config.js"
    keepOutputDirectory: true
    packager: "npm"
    includeModules:
      nodeModulesRelativeDir: "../../"

This leads to a webpack compile time error: npm ERR! 404 Not Found - GET https://registry.npmjs.org/@nighttrax%2fbar - Not found

Not sure why, but I believe this is due to the way serverless-webpack handles dependencies. I believe they try to bundle with webpack and do an npm install in the webpack ouput folder.

I extended the repo to showcase this (NPM branch): https://github.com/florianbepunkt/ts-monorepo/tree/npm

In case anyone finds a solution for this, a heads up would be nice.

@derek-lewis
Copy link
Author

I managed to build a perfect solution using workspaces and serverless-optimize. The only complication was that mongodb needs to be extracted into a lambda layer and installed locally as a devDep.

@florianbepunkt
Copy link

@derek-lewis Do you have an example repo by any chance?

@derek-lewis
Copy link
Author

I will look to get an example repo up for you 👍🏼

@vjcspy
Copy link

vjcspy commented Dec 25, 2022

@derek-lewis i have created a pull request for serverless application #303

Repository owner locked and limited conversation to collaborators Jun 10, 2023
@NiGhTTraX NiGhTTraX converted this issue into discussion #315 Jun 10, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants