domeccleston / langchain-ts-starter

Langchain.js template to get started quickly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESM Build start : [ERROR] Top-level await is not available in the configured target environment ("es2017")

Bakann opened this issue · comments

commented

Hello everyone,

I've just cloned this repo and followed the instruction, but I get this error below when building the project. I've changed the target to es2020 but I got the same error :

➜ langchain-ts-starter git:(main) ✗ npx turbo run build lint format
• Running build, lint, format
• Remote caching disabled
lint: Skipping cache check for //#lint, outputs have not changed since previous run.
lint: cache hit, replaying output ba1d93610b79d22b
format: Skipping cache check for //#format, outputs have not changed since previous run.
format: cache hit, replaying output b62b0263feb4282c
build: cache miss, executing c0464e17a9d1b044
lint:
lint: > langchain-ts-starter@1.0.0 lint
lint: > eslint src
lint:
format:
format: > langchain-ts-starter@1.0.0 format
format: > prettier --write "**/*.ts"
format:
format: dist/index.d.ts 278ms
format: src/index.ts 34ms
build:
build: > langchain-ts-starter@1.0.0 build
build: > tsup
build:
build: CLI Building entry: src/index.ts
build: CLI Using tsconfig: tsconfig.json
build: CLI tsup v6.7.0
build: CLI Using tsup config: /Users/bakanndy/may/langchain-ts-starter/tsup.config.js
build: CLI Target: es2017
build: CLI Cleaning output folder
build: CJS Build start
build: ESM Build start
build: ✘ [ERROR] Top-level await is not available in the configured target environment ("es2017")
build:
build: src/index.ts:11:12:
build: 11 │ const res = await model.call(
build: ╵ ~~~~~
build:
build: ✘ [ERROR] Top-level await is not available in the configured target environment ("es2017")
build:
build: src/index.ts:11:12:
build: 11 │ const res = await model.call(
build: ╵ ~~~~~
build:
build: CJS Build failed
build: Error: Build failed with 1 error:
build: src/index.ts:11:12: ERROR: Top-level await is not available in the configured target environment ("es2017")
build: at failureErrorWithLog (/Users/bakanndy/may/langchain-ts-starter/node_modules/esbuild/lib/main.js:1636:15)
build: at /Users/bakanndy/may/langchain-ts-starter/node_modules/esbuild/lib/main.js:1048:25
build: at runOnEndCallbacks (/Users/bakanndy/may/langchain-ts-starter/node_modules/esbuild/lib/main.js:1471:45)
build: at buildResponseToResult (/Users/bakanndy/may/langchain-ts-starter/node_modules/esbuild/lib/main.js:1046:7)
build: at /Users/bakanndy/may/langchain-ts-starter/node_modules/esbuild/lib/main.js:1075:16
build: at responseCallbacks. (/Users/bakanndy/may/langchain-ts-starter/node_modules/esbuild/lib/main.js:697:9)
build: at handleIncomingPacket (/Users/bakanndy/may/langchain-ts-starter/node_modules/esbuild/lib/main.js:752:9)
build: at Socket.readFromStdout (/Users/bakanndy/may/langchain-ts-starter/node_modules/esbuild/lib/main.js:673:7)
build: at Socket.emit (node:events:390:28)
build: at addChunk (node:internal/streams/readable:315:12)
build: ESM Build failed
build: DTS Build start
build: DTS ⚡️ Build success in 2160ms
build: DTS dist/index.d.ts 12.00 B
build: ERROR: command finished with error: command (/Users/bakanndy/may/langchain-ts-starter) npm run build exited (1)
command (/Users/bakanndy/may/langchain-ts-starter) npm run build exited (1)

Tasks: 2 successful, 3 total
Cached: 2 cached, 3 total
Time: 3.551s
Failed: //#build

ERROR run failed: command exited (1)
➜ langchain-ts-starter git:(main) ✗

I have the same issue

I just finished fixing the same issue as this. This is what I did.

(async() => {
 await my_top_level_await_problem();
})();

Alternatively you could target ES2022 in the tsconfig.json:
"target": "ES2022"

and remove "cjs" import format in tsup.config.js:
format: ["esm"]

but for the repo, it would probably be better if the example was rewritten to use an IIFE wrapping an async function as above, since you'd lose some of the user base on older node versions.

Also faced the same issue and @ochsec workaround did the trick, thanks!

I fixed it.

(async() => {
  const res = await model.call(
    "What's a good idea for an application to build with GPT-3?"
  );
  console.log("what is it?",res);
 })();

image