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

[vite] Pre-transform error: Failed to convert napi value into rust type bool #18272

Closed
7 tasks done
AbderrahmenISSA opened this issue Oct 3, 2024 · 12 comments
Closed
7 tasks done

Comments

@AbderrahmenISSA
Copy link

Describe the bug

I can't build a docker image from my simple VITE project

Reproduction

Localhost

Steps to reproduce

docker build image
docker run image_id

System Info

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 122.48 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.9.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.8.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 129.0.6668.72
    Safari: 17.6
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1 
    vite: ^5.3.1 => 5.3.2

Used Package Manager

npm

Logs

No response

Validations

@paulocheque
Copy link

paulocheque commented Oct 3, 2024

Start to happen here too after updating the libs (Vite 5.3.5 to 5.4.8). I didn't indentify yet, then follow the stack trace that should help others.

[plugin:vite:import-analysis] Failed to convert napi value into rust type bool

at parseAst (file:///app/node_modules/rollup/dist/es/shared/parseAst.js:1909:102)
    at transformCjsImport (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:64110:16)
    at interopNamedImports (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:64082:23)
    at file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:63871:19
    at async Promise.all (index 0)
    at async TransformPluginContext.transform (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:63774:7)
    at async PluginContainer.transform (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:48786:18)
    at async loadAndTransform (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:51608:27)
    at async viteTransformMiddleware (file:///app/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:61557:24

Copy link

github-actions bot commented Oct 4, 2024

Hello @AbderrahmenISSA. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@ptrwilk
Copy link

ptrwilk commented Oct 4, 2024

@AbderrahmenISSA I had the same problem. I added .dockerignore file including node_modules entiry. And that fixed the issue.

@AbderrahmenISSA
Copy link
Author

Hello, The solution I finally found after many tries :

  • Use node:18 instead of latest or alpine version
  • Use npm ci instead of npm install
  • Add CMD npm run $NODE_ENV -- --host 0.0.0.0 --port 3000

So my final dockerfile is :

FROM node:18

WORKDIR /usr/src/app

# Set PATH to include local node_modules
ENV PATH /usr/src/node_modules/.bin:$PATH

# Set environment variable (local, dev, prd)
ARG environment
ENV NODE_ENV=$environment
RUN echo $NODE_ENV

# Copy package.json and package-lock.json
COPY package.json package-lock.json ./

# Install dependencies
RUN npm ci

# Copy the rest of the application code
COPY . ./

# Expose the port that the app runs on
EXPOSE 3000

# Start the Vite app
CMD npm run $NODE_ENV -- --host 0.0.0.0 --port 3000

@DiegoLibonati
Copy link

DiegoLibonati commented Oct 4, 2024

Not working any solution in my case

image

Dockerfile:

FROM node:18-alpine3.18

WORKDIR /home/app

COPY ./package*.json .

RUN yarn install

COPY . .

EXPOSE 5173

CMD ["yarn", "run", "dev", "--host"]

Compose:

  client:
    build:
      context: ./json-client
      dockerfile: Dockerfile.development
    restart: always
    ports:
      - "5173:5173"
    env_file:
      - ./json-config/client.env
    volumes:
      - ./json-client/src:/home/app/src
      - /home/app/node_modules
    networks:
      - net-json-transformer

@DiegoLibonati
Copy link

Okay, I solved it. I made 3 changes:

  • FROM node:18-alpine3.18 to FROM node:21.1.0-alpine3.18
  • I added a .dockerignore in my react project folder. At the same level as the package.json. With the following line: node_modules
  • I removed the line of the docker-compose that belonged to a volume: /home/app/node_modules

@apeman76
Copy link

apeman76 commented Oct 4, 2024

This is definitely some new issue, using Vite 5.3.5 works totally fine but using latest version "vite": "^5.4.8" will always give this error.

@L1ghtError
Copy link

Try to update vitejs/plugin-react-swc to at least 3.7.1

@Fahad-ishfaq
Copy link

I had same issue,
Dockerfile

FROM node:18-alpine3.19 AS build
WORKDIR /app
COPY package.json .
RUN npm i
COPY . .
RUN npm run build

Vite version 5.3.1

Fix
removing node_modules directory fixed this issue

@BrendanJM
Copy link

I'm not sure why adding node_modules to .dockerignore didn't work for me (even after removing a reference to it as a volume), but deleting my local node_modules dir resolved it.

@femke77
Copy link

femke77 commented Oct 17, 2024

having the same error but not with Docker. Just trying to deploy to Render.com. Fails with this same error.

@DiegoLibonati
Copy link

having the same error but not with Docker. Just trying to deploy to Render.com. Fails with this same error.

try with: Vite 5.3.5

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

No branches or pull requests

10 participants