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 bundle axios,superagent Uncaught Error: Dynamic require of "util" is not supported #709

Closed
ajiehatajie opened this issue Sep 3, 2022 · 13 comments

Comments

@ajiehatajie
Copy link

Uncaught Error: Dynamic require of "util" is not supported
at index.mjs:12:9
at ../../node_modules/combined-stream/lib/combined_stream.js (index.mjs:2776:16)
at __require2 (index.mjs:15:17)
at ../../node_modules/axios/node_modules/form-data/lib/form_data.js (index.mjs:11791:26)
at __require2 (index.mjs:15:17)
at ../../node_modules/axios/lib/defaults/env/FormData.js (index.mjs:12104:22)
at __require2 (index.mjs:15:17)
at ../../node_modules/axios/lib/defaults/index.js (index.mjs:12200:19)
at __require2 (index.mjs:15:17)
at ../../node_modules/axios/lib/core/transformData.js (index.mjs:12226:20)

"build": "tsup src/index.ts --format esm,cjs --dts --external react axios ",
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react axios",

@ajiehatajie ajiehatajie changed the title error bundle axios,superagent error bundle axios,superagent Uncaught Error: Dynamic require of "util" is not supported Sep 3, 2022
@lvqq
Copy link

lvqq commented Sep 5, 2022

esbuildOptions: (options) => {
  options.banner = {
    js: "import { createRequire } from 'module';const require = createRequire(import.meta.url);",
  }
}

Maybe the above esbuildOption in tsup.config.ts can help it

@ajiehatajie
Copy link
Author

import { createRequire } from 'module';const require = createRequire(import.meta.url)

[ERROR] Expected "}" but found "file"

tsup.config.ts:3:79:
  3 │ ...om 'module';const require = createRequire("file:///Users/legit-group/Documents/Works/Legi...
    │                                               ~~~~
    ╵

@lvqq
Copy link

lvqq commented Sep 5, 2022

It's an related issue with evanw/esbuild#1921, you can try the mentioned solution.

@mahaoming
Copy link

I also have the same problem. Have you fixed it

@mahaoming
Copy link

image

@mahaoming
Copy link

mahaoming commented Sep 16, 2022

export default defineConfig((options: Options) => ({
  entry: ['src/index.ts'],
  dts: true,
  clean: true,
  format: ['esm'],
  esbuildOptions: (options) => {
    options.banner = {
      js: `import { createRequire } from 'module'; const require = createRequire(import.meta.url);`,
    }
  },
  ...options,
}))

this is my tsup.config

@mahaoming
Copy link

Uncaught Error: Dynamic require of "util" is not supported at index.mjs:12:9 at ../../node_modules/combined-stream/lib/combined_stream.js (index.mjs:2776:16) at __require2 (index.mjs:15:17) at ../../node_modules/axios/node_modules/form-data/lib/form_data.js (index.mjs:11791:26) at __require2 (index.mjs:15:17) at ../../node_modules/axios/lib/defaults/env/FormData.js (index.mjs:12104:22) at __require2 (index.mjs:15:17) at ../../node_modules/axios/lib/defaults/index.js (index.mjs:12200:19) at __require2 (index.mjs:15:17) at ../../node_modules/axios/lib/core/transformData.js (index.mjs:12226:20)

"build": "tsup src/index.ts --format esm,cjs --dts --external react axios ", "dev": "tsup src/index.ts --format esm,cjs --watch --dts --external react axios",

Did you solve it

@lvqq
Copy link

lvqq commented Sep 19, 2022

tsup has an bug with banner, refer: #719, just try other solution

@egoist
Copy link
Owner

egoist commented Nov 3, 2022

you need --external react --external axios to externalize both modules instead of --external react axios

@egoist egoist closed this as completed Nov 3, 2022
@mahaoming
Copy link

you need --external react --external axios to externalize both modules instead of --external react axios

had add external, but it not work for me

@mahaoming
Copy link

you need --external react --external axios to externalize both modules instead of --external react axios

image

@amosmachora
Copy link

I don't think there is a clear answer. Still running into the same problem.

i use tsup in my ci/cd pipeline

"build": "tsup index.ts --format cjs,esm --dts --external axios",

I don't have a tsup.config file. Should i add one and if so what should i add to get rid of the error.
Error: Dynamic require of "axios" is not supported

@amosmachora
Copy link

you need --external react --external axios to externalize both modules instead of --external react axios

This doesn't seem to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants