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

Not working with aws-cli / aws-amplify #1374

Closed
sem4phor opened this issue Jan 5, 2021 · 2 comments
Closed

Not working with aws-cli / aws-amplify #1374

sem4phor opened this issue Jan 5, 2021 · 2 comments
Labels
wontfix This will not be worked on

Comments

@sem4phor
Copy link

sem4phor commented Jan 5, 2021

Describe the bug

After installing vite and adding aws-amplify I get following error message:

[plugin:vite:imports] Failed to resolve import "process". Does the file exist?
/Users/XXXXX/node_modules/@aws-sdk/util-user-agent-node/dist/es/index.js:1:22
1  |  import process from "process";
   |                       ^
2  |  export function defaultUserAgent(packageName, packageVersion) {
3  |      var engine = process.platform + "/" + process.version;
Error: Failed to resolve import "process". Does the file exist?
    at TransformContext.error (C:\Users\XXXXX\node_modules\vite\dist\node\chunks\dep-262f13eb.js:59552:50)
    at TransformContext.transform (C:\XXXXX\node_modules\vite\dist\node\chunks\dep-262f13eb.js:52957:30)
    at async Object.transform (C:\Users\XXXXX\node_modules\vite\dist\node\chunks\dep-262f13eb.js:59742:30)
    at async transformRequest (C:\Users\XXXXX\node_modules\vite\dist\node\chunks\dep-262f13eb.js:65977:29)
    at async C:\Users\XXXXX\node_modules\vite\dist\node\chunks\dep-262f13eb.js:66068:32

Obviously the AWS Package can not resolve nodeBuiltins.
I tried to exclude the aws packages from dependency optimization and also tried to add them to the allowNodeBuiltins option in various combinations e.g. as follows:

// vite.config.js
optimizeDeps: {
    allowNodeBuiltins: [
      'aws-amplify', '@aws-cli'
    ]
 },

Is it more like a problem of the aws-cli package? Or are there any known workarounds?

Reproduction

Download https://github.com/sem4phor/aws-cli-bug
Run npm run dev
See error in console
Modify vite.config to allowNodeBuiltins and nothing happens

System Info

  • required vite version: 2.0.0beta5
  • required Operating System: Windows 10
  • required Node version: 15.2
  • Optional:
    • npm version 6.14.9
@yyx990803 yyx990803 added wontfix This will not be worked on and removed pending triage labels Jan 5, 2021
@yyx990803
Copy link
Member

yyx990803 commented Jan 5, 2021

This is a wont fix, because aws-amplify is legit trying to import and use Node-only builtins when it's actually intended to be a client library. Unlike webpack 4, Vite does not shim Node built-ins. Note this means aws-amplify will break in webpack 5 as well because it no longer shims Node built-ins.

aws-amplify should stop relying on Node built-ins if it actually is meant to be used in the browser.

@hkjpotato
Copy link

hkjpotato commented Jul 8, 2021

aws-amplify depends on aws-sdk, which has upgraded itself to differentiate the node and js runtime by using the browser field. However, its browser field setting is as follows:

"browser": {
     "./runtimeConfig": "./runtimeConfig.browser" 
     // it means if a file A encounters a relative path import
    // find the "browser" file using the path relative to file A, not the root
}

Currently this relative path could confuse vite resolver.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants