farm-fe / farm

Extremely fast Vite-compatible web build tool written in Rust
https://farmfe.org
MIT License
5.05k stars 165 forks source link

[Bug Report]: Expected ';', '}' or <eof> and Expected Declaration value #1557

Closed rawbin- closed 1 month ago

rawbin- commented 4 months ago

Steps to reproduce

pnpm install pnpm build

Reproduce link

https://github.com/rawbin-/farm-repro

What is actually happening?

import Highlighter from 'react-highlight-words';
image image
import 'dhtmlx-gantt/codebase/dhtmlxgantt.css';
image

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1 Pro
    Memory: 81.94 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.2.0 - ~/.volta/tools/image/node/22.2.0/bin/node
    Yarn: 1.22.22 - ~/.volta/tools/image/yarn/1.22.22/bin/yarn
    npm: 10.7.0 - ~/.volta/tools/image/node/22.2.0/bin/npm
    pnpm: 9.1.1 - ~/.volta/tools/image/pnpm/9.1.1/bin/pnpm
  Browsers:
    Chrome: 126.0.6478.127
    Chrome Canary: 128.0.6583.0
    Edge: 126.0.2592.87
    Safari: 17.5
wre232114 commented 4 months ago

Could you please provide a repo that can reproduce this issue, we need more details to locate the issue

rawbin- commented 4 months ago

It seems the js error occurs when we have this config, but the css error shows up always

image
fu050409 commented 4 months ago

It seems the js error occurs when we have this config, but the css error shows up always image

This is truely caused by this define but I think it's not a bug. It works like #define in C/C++, macro definitions are essentially macro substitutions, all keywords process.env will be replaced with the value of itself. So the expression process.env = {}; will be replaced to a expr like { ...process.env } = {}; so a syntax error will be thrown.

rawbin- commented 4 months ago

It seems the js error occurs when we have this config, but the css error shows up always image

This is truely caused by this define but I think it's not a bug. It works like #define in C/C++, macro definitions are essentially macro substitutions, all keywords process.env will be replaced with the value of itself. So the expression process.env = {}; will be replaced to a expr like { ...process.env } = {}; so a syntax error will be thrown.

What's the difference with vite? when I use vite to build, it works fine. But when migrated to farm, it is stuck.

wre232114 commented 4 months ago

We'll take a look

wre232114 commented 1 month ago

The css issue will be fixed in @farmfe/core@1.3.28. But define whole process.env is not supported in farm, it's unsafe, you can use env config to specify the env you want to define