Setup is failing on running yarn build
with no changes on new workspace
#5294
Replies: 4 comments 9 replies
-
The error you're encountering is due to Node.js's strict handling of ECMAScript Modules (ESM), particularly around the requirement for file extensions in import statements. Since your project is using Node.js version 20.2.0 and is configured with
By following these steps, you should be able to resolve the build issue. If the problem persists, ensure you're providing detailed information about your environment and the exact error messages for further assistance.
|
Beta Was this translation helpful? Give feedback.
-
The change introduced into the project only one week ago via this PR
https://github.com/langchain-ai/langchainjs/pull/5268/files
has resulted in a broken build, both on windows as well as linux (with or
without the dev container usage)
…On Sat, May 11, 2024, 11:02 dosubot[bot] ***@***.***> wrote:
To address the "TypeError [ERR_UNKNOWN_FILE_EXTENSION]" error you're
encountering due to Node.js's strict handling of ECMAScript Modules (ESM)
and the lack of file extension for the @langchain/scripts package's
bin/build file, consider implementing a custom loader. This solution
allows Node.js to process the file without directly modifying the package.
Here's a concise guide:
1. *Create a Custom Loader*: Write a custom loader in a file, say
custom-loader.mjs, that exports a load function. This function will
instruct Node.js on how to handle the specific file causing the issue.
// custom-loader.mjsexport async function load(url, context, defaultLoad) {
if (url.endsWith('.customext')) { // Adjust '.customext' to match the problematic extension
const { source } = await defaultLoad(url, { format: 'module' }, defaultLoad);
const transformedSource = source; // Implement any necessary transformation here
return { format: 'module', source: transformedSource };
}
return defaultLoad(url, context, defaultLoad);}
2. *Use the Custom Loader*: Modify your build command to utilize the
custom loader by adding the --loader flag to the Node.js command.
"scripts": {
"build": "node --loader ./path/to/custom-loader.mjs your-build-script.js"
}
Replace ./path/to/custom-loader.mjs with the path to your loader and
your-build-script.js with the entry point to your build script.
This method allows Node.js to understand and process the file correctly,
circumventing the need to alter the @langchain/scripts package.
Details
*Sources*
- package.json
<https://github.com/langchain-ai/langchainjs/blob/main/package.json>
- libs/langchain-scripts/package.json
<https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-scripts/package.json>
- libs/langchain-scripts/README.md
<https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-scripts/README.md>
- langchain/langchain.config.js
<https://github.com/langchain-ai/langchainjs/blob/main/langchain/langchain.config.js>
- langchain/tsconfig.cjs.json
<https://github.com/langchain-ai/langchainjs/blob/main/langchain/tsconfig.cjs.json>
- langchain/tsconfig.json
<https://github.com/langchain-ai/langchainjs/blob/main/langchain/tsconfig.json>
- libs/langchain-exa/tsconfig.cjs.json
<https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-exa/tsconfig.cjs.json>
- langchain/package.json
<https://github.com/langchain-ai/langchainjs/blob/main/langchain/package.json>
- langchain/src/document_loaders/fs/notion.ts
<https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/document_loaders/fs/notion.ts>
- libs/langchain-scripts/bin/build
<https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-scripts/bin/build>
- libs/langchain-scripts/src/build.ts
<https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-scripts/src/build.ts>
- langchain-core/tsconfig.json
<https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/tsconfig.json>
- langchain-core/tsconfig.cjs.json
<https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/tsconfig.cjs.json>
- libs/langchain-scripts/tsconfig.cjs.json
<https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-scripts/tsconfig.cjs.json>
- .devcontainer/devcontainer.json
<https://github.com/langchain-ai/langchainjs/blob/main/.devcontainer/devcontainer.json>
- langchain-core/package.json
<https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/package.json>
*About Dosu*
This response is meant to be useful and save you time. It is *not meant
to be a precise solution*, but rather a starting point for your own
research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it
is irrelevant.
*To continue the conversation, mention @dosu <https://github.com/dosu>.*
—
Reply to this email directly, view it on GitHub
<#5294 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4N67RE5HPAHVVWFJWH7LZBXNEFAVCNFSM6AAAAABHJRTA5KVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TGOJTHA4TC>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
I had this problem on Node.js 18.17.0:
And I solved it by upgrading to LTS (20.13.1):
|
Beta Was this translation helpful? Give feedback.
-
I have tried with a slightly older version of langchain and it worked for me. Issue can be closed. |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
NA
Description
I am trying to modify the
langchain/openai
package. In order to do that, I created a new github workspace for the langchainjs project and followed the steps in contributing.md file:The following error happens:
I am surprised on this failure since it is working fine for others. So, something is either missing or somehow it is not working on github workspaces. Can someone please take a look?
System Info
Yarn Version: 3.4.1
Node version: 20.2.0
Beta Was this translation helpful? Give feedback.
All reactions