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

MS Azure - Could not import faiss-node ... faiss-node.node is not a valid Win32 application #6148

Closed
5 tasks done
jacknkandy opened this issue Jul 19, 2024 · 3 comments
Closed
5 tasks done
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@jacknkandy
Copy link

jacknkandy commented Jul 19, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

import statement:

import { FaissStore } from '@langchain/community/vectorstores/faiss';

package.json

{
    "name": "pdf-chat-prototype",
    "version": "0.1.0",
    "description": "",
    "scripts": {
        "ingest": "tsx -r dotenv/config scripts/ingest.ts",
        "start": "nodemon --exec ts-node ./src/index.ts",
        "build": "npx tsc"
    },
    "dependencies": {
        "@fastify/cors": "^9.0.1",
        "@langchain/community": "^0.2.19",
        "@langchain/core": "^0.2.17",
        "@langchain/openai": "^0.2.4",
        "ajv-errors": "^3.0.0",
        "ajv-formats": "^3.0.1",
        "dotenv": "^16.4.5",
        "faiss-node": "^0.5.1",
        "fastify": "^4.28.1",
        "langchain": "^0.2.10",
        "moment": "^2.30.1",
        "pdf-parse": "^1.1.1"
    },
    "devDependencies": {
        "@types/pdf-parse": "^1.1.4",
        "nodemon": "^3.1.4",
        "ts-node": "^10.9.2",
        "tsx": "^4.16.2",
        "typescript": "^5.5.3"
    },
    "engines": {
        "node": ">=18"
    }
}

GitHub Actions:

name: Build and deploy Node.js app to Azure Web App - mecone-chat-bot

on:
  push:
    branches:
      - azure-prod
  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: '18.x'

      - name: npm install
        run: |
          npm install

      - name: npm build
        run: |
          npm run build --if-present
    
      - name: Compress artifact before upload
        uses: a7ul/[email protected]
        id: compress
        with:
          command: c
          cwd: ./
          files: |
            ./dist
            ./node_modules
            ./vectors
            ./web.config
          outPath: release.tar.gz
      
      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: node-app
          path: ./release.tar.gz

  deploy:
    runs-on: windows-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    permissions:
      id-token: write #This is required for requesting the JWT

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: node-app

      - name: Extract artifact for before deployment
        uses: a7ul/[email protected]
        id: extract
        with:
          command: x
          cwd: ./
          files: release.tar.gz

      - name: Remove archive before deployment
        run: |
          rm release.tar.gz
      
      - name: Login to Azure
        uses: azure/login@v2
        with:
          client-id: ###
          tenant-id: ###
          subscription-id: ###

      - name: 'Deploy to Azure Web App'
        uses: azure/webapps-deploy@v3
        id: deploy-to-webapp
        with:
          app-name: 'mecone-chat-bot'
          slot-name: 'Production'
          package: .

Error Message and Stack Trace (if applicable)

Could not import faiss-node. Please install faiss-node as a dependency with, e.g. npm install -S faiss-node.\n\nError: \\?\C:\home\site\wwwroot\node_modules\faiss-node\build\Release\faiss-node.node is not a valid Win32 application.\r\n\\?\C:\home\site\wwwroot\node_modules\faiss-node\build\Release\faiss-node.node

Description

Hi there,

I am having issues getting a sample app to run on an Azure Web App service. I can confirm that my app is working locally fine (MacOS) but am getting the following error after having built and deployed to a Windows-based Azure Web App service.

Could not import faiss-node. Please install faiss-node as a dependency with, e.g. `npm install -S faiss-node`.\n\nError: \\\\?\\C:\\home\\site\\wwwroot\\node_modules\\faiss-node\\build\\Release\\faiss-node.node is not a valid Win32 application.\r\n\\\\?\\C:\\home\\site\\wwwroot\\node_modules\\faiss-node\\build\\Release\\faiss-node.node

I am deploying via a GitHub actions deployment script, and have made sure that it is being built and deployed for using a Windows-based build server.

I can see a variety of similar issues reported for AWS etc. but cannot find a solution that works for me.

#5843
#5164
#4027
#3941

My error is slightly different as it is complaining that the faiss-node.node file is not a valid Win32 application.

I can locate the file mentioned in the path, running Node v18 on the Web App.

image

I have tried installing the package locally using npm i faiss-node via my Azure Web app, this didn't work. Additionally I tried dropping in the files from the pre-built release from faiss-node-v0.5.1-napi-v6-win32-x64.tar.gz again this didn't change anything.

Any help or guidance would be appreciated!

System Info

platform: Windows
langchain 0.2.10
node 18.19.1

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jul 19, 2024
Copy link

dosubot bot commented Jul 19, 2024

Hey there, @jacknkandy! I'm here to help you with your technical questions and bug fixes. Let's tackle this issue together while we wait for a human maintainer to jump in.

To resolve the error related to faiss-node in your Azure Web App service, follow these steps:

  1. Install faiss-node:
    Ensure faiss-node is installed as a dependency:

    npm install -S faiss-node
  2. Adjust @rollup/plugin-commonjs Configuration:
    Create or update your Rollup configuration file (e.g., rollup.config.js) to include the dynamicRequireTargets option for @rollup/plugin-commonjs:

    import commonjs from '@rollup/plugin-commonjs';
    
    export default {
      // other Rollup configuration options
      plugins: [
        commonjs({
          dynamicRequireTargets: [
            'node_modules/faiss-node/**/*'
          ],
          ignoreDynamicRequires: true
        })
      ]
    };
  3. Ensure Proper Import in Code:
    In your main process file (e.g., main.js or index.js), ensure the import of faiss-node is handled correctly. Add the following code snippet to handle the import:

    static async importFaiss(): Promise<{ IndexFlatL2: typeof IndexFlatL2 }> {
      try {
        const {
          default: { IndexFlatL2 },
        } = await import("faiss-node");
    
        return { IndexFlatL2 };
      } catch (err: any) {
        throw new Error(
          `Could not import faiss-node. Please install faiss-node as a dependency with, e.g. \`npm install -S faiss-node\`.\n\nError: ${err?.message}`
        );
      }
    }
  4. Configure Azure Web App for Native Modules:
    Create a custom startup script (e.g., startup.sh) to install any additional dependencies and set up the environment. This script can be used to install system-level dependencies that faiss-node might require.

    Example startup.sh script:

    #!/bin/bash
    
    # Install system-level dependencies required by faiss-node
    apt-get update && apt-get install -y build-essential
    
    # Navigate to the app directory
    cd /home/site/wwwroot
    
    # Install npm dependencies
    npm install
    
    # Start the application
    npm start

    Ensure the script is executable:

    chmod +x startup.sh

    Add the custom startup script to your Azure Web App configuration:

    • Name: WEBSITE_RUN_FROM_PACKAGE
    • Value: 1
    • Name: STARTUP_COMMAND
    • Value: bash startup.sh

By following these steps, you can ensure that the Azure Web App service is configured to support native modules like faiss-node [1][2].

To continue talking to Dosu, mention @dosu.

@jacknkandy jacknkandy changed the title Could not import faiss-node ... \\C:\\home\\site\\wwwroot\\node_modules\\faiss-node\\build\\Release\\faiss-node.node is not a valid Win32 application MS Azure - Could not import faiss-node ... faiss-node.node is not a valid Win32 application Jul 19, 2024
@jacknkandy
Copy link
Author

jacknkandy commented Aug 5, 2024

Just an update - I switched out and set up a new Linux-based Web App and was able to get my app to run without any hiccups. I believe there is some compatibility issue with the Windows-based build of faiss-node in Azure (potentially along the lines of ewfian/faiss-node#25) but was unable to investigate any further.

Copy link

dosubot bot commented Nov 4, 2024

Updated comment text: Hi, @jacknkandy! I'm helping the LangChain JS team manage their backlog and am marking this issue as stale.

From what I understand, you initially faced difficulties importing the faiss-node package in a Node.js application on an Azure Web App due to an error with the faiss-node.node file. After some guidance from me, you found success by switching to a Linux-based Web App, which suggests a compatibility issue with the Windows build of faiss-node.

Could you please confirm if this issue is still relevant to the latest version of the LangChain JS repository? If it is, let the team know by commenting here. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 4, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant