Skip to content
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

Error trying to use serverless-esbuild with serverless-offline on Mac M1 #454

Closed
artur-rod opened this issue Mar 23, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@artur-rod
Copy link

Describe the bug
I just started a serverless project using aws-nodejs-typescript template, installed the dependencies with yarn and when I try to run sls offline, I'm getting this error:

You installed esbuild for another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.

Specifically the "@esbuild/darwin-arm64" package is present but this platform
needs the "@esbuild/darwin-x64" package instead. People often get into this
situation by installing esbuild with npm running inside of Rosetta 2 and then
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
2 is Apple's on-the-fly x86_64-to-arm64 translation service).

If you are installing with npm, you can try ensuring that both npm and node are
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
changing how you installed npm and/or node. For example, installing node with
the universal installer here should work: https://nodejs.org/en/download/. Or
you could consider using yarn instead of npm which has built-in support for
installing a package on multiple platforms simultaneously.

If you are installing with yarn, you can try listing both "arm64" and "x64"
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.

Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.

To Reproduce
Steps to reproduce the behavior.

  1. Run serverless create --template aws-nodejs-typescript --path ignite-serverless-challenge to create a new project
  2. Run yarn to install the dependencies
  3. Run sls offline

Expected behavior
Expect serverless function to run offline.

Screenshots or Logs
image

Versions (please complete the following information):

  • OS: Mac (on M1 Chip)
  • Serverless Framework Version: 3.0.0
  • Plugin Version: 1.17.1
  • Serverless Offline Version: 12.0.4

Additional context
I already tried the advice on the error to set up os and cpu on a .yarnrc.yml file, and added to package.jsontoo, but no success.
Also, I changed from serverless.tsto serverless.ymlconfig file.
image
image

@artur-rod artur-rod added the bug Something isn't working label Mar 23, 2023
@floydspace
Copy link
Owner

Hi @artur-rod
I don't think it's the issue of this plugin, but the esbuild bundler itself.
However, I noticed you use node 19, but in printed error it's stated node 16, kinda weird.
Could you maybe try to use node 16 or node 18 in your shell? And obviously reinstall dependencies.
Also, I'd suggest try npm instead of yarn just to eliminate variants

@fredrik
Copy link
Contributor

fredrik commented Mar 29, 2023

Hey @artur-rod, I tried recreating your issue on my M1 Macbook but could not. It works fine with both npm and yarn for me.

I've installed Node via nvm, which I recommend you try if you haven't.

For what it's worth, here are my versions in this templated project:

❯ npm --version
9.5.0
❯ node --version
v18.14.2
❯ yarn --version
1.22.19


❯ npm list
[email protected] /private/tmp/ignite-serverless-challenge
├── @middy/[email protected]
├── @middy/[email protected]
├── @serverless/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

@artur-rod
Copy link
Author

Hey guys, thanks for the help.
I solved the issue by running the terminal with Rosetta 2, reinstalling node with x64 architecture (following the steps in the NVM page, link here) and then reinstalling all the project dependencies.

Also, I wroted a article about that, but in portuguese, link here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants