Skip to content

[Bug Report]: farm build failed #2169

@houkunlin

Description

@houkunlin

Steps to reproduce

farm build failed

Reproduce link

No response

What is actually happening?

use @tanstack/react-router , then farm build failed.

npm list:

PS D:\workspace\xxx> npm list
[email protected] D:\workspace\xxx
+-- @ant-design/[email protected]
+-- @ant-design/[email protected]
+-- @ant-design/[email protected]
+-- @ant-design/[email protected]
+-- @ant-design/[email protected]
+-- @codemirror/[email protected]
+-- @codemirror/[email protected]
+-- @codemirror/[email protected]
+-- @emotion/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @farmfe/[email protected]
+-- @swc/[email protected]
+-- @tanstack/[email protected]
+-- @tanstack/[email protected]
+-- @tanstack/[email protected]
+-- @tanstack/[email protected]
+-- @testing-library/[email protected]
+-- @types/[email protected]
+-- @types/[email protected]
+-- @types/[email protected]
+-- @types/[email protected]
+-- @uiw/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

npm run build log:

♻️  Generating routes...
✅ Processed routes in 341ms
[ building ] ⠄ transform (523) node_modules/antd/es/back-top/style/index.js                                                                                                                                                                                           
Parse `src/routes/__root.tsx` failed.
 Error:   × Expression expected
    ╭─[src/routes/__root.tsx:14:1]
 11 │ })
 12 │
 13 │ function RootLayout() {
 14 │   return <>
    ·          ─
 15 │     <HeadContent />
 16 │     <Outlet />
 17 │     <Scripts />
    ╰────
  × Expression expected
    ╭─[src/routes/__root.tsx:14:1]
 11 │ })
 12 │
 13 │ function RootLayout() {
 14 │   return <>
    ·           ─
 15 │     <HeadContent />
 16 │     <Outlet />
 17 │     <Scripts />
    ╰────

Potential Causes:
1.The module have syntax error.
2.This kind of module is not supported, you may need plugins to support it

thread '<unnamed>' panicked at rust-plugins\strip\src\lib.rs:112:9:
Parse src/routes/__root.tsx failed. See error details above.
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[ building ] ⠄ transform (591) node_modules/@ant-design/icons-svg/es/asn/DownOutlined.js                                                                                                                                                                              
:
panic in a function that cannot unwind
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.

or npm run build log:

♻️  Generating routes...
✅ Processed routes in 336ms
[ building ] ⠂ transform (111) node_modules/core-js/internals/environment-user-agent.js.farm-runtime                                                                                                                                                                  
Parse `src/routes/__root.tsx` failed.
 Error:   × Expression expected
    ╭─[src/routes/__root.tsx:14:1]
 11 │ })
 12 │ 
 13 │ function RootLayout() {
 14 │   return <>
    ·          ─
 15 │     <HeadContent />
 16 │     <Outlet />
 17 │     <Scripts />
    ╰────
  × Expression expected
    ╭─[src/routes/__root.tsx:14:1]
 11 │ })
 12 │
 13 │ function RootLayout() {
 14 │   return <>
    ·           ─
 15 │     <HeadContent />
 16 │     <Outlet />
 17 │     <Scripts />
    ╰────

Potential Causes:
1.The module have syntax error.
2.This kind of module is not supported, you may need plugins to support it

thread '<unnamed>' panicked at rust-plugins\strip\src\lib.rs:112:9:
Parse src/routes/__root.tsx failed. See error details above.
stack backtrace:
[ building ] ⠂ transform (193) src/pages/system/SysWechatOfficialAccountConfig/FormPage.tsx                                                                                                                                                                           
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Parse `src/layouts/layout.tsx` failed.
 Error:   × Expected ',', got '{'
   ╭─[src/layouts/layout.tsx:2:1]
 1 │ import { GithubFilled, InfoCircleFilled, LogoutOutlined, QuestionCircleFilled } from '@ant-design/icons';
 2 │ import type { ProSettings } from '@ant-design/pro-components';
   ·             ─
 3 │ import { ProLayout, SettingDrawer } from '@ant-design/pro-components';
 4 │ import { Dropdown } from 'antd';
 5 │ import { useMemo, useState } from 'react';
   ╰────

Potential Causes:
1.The module have syntax error.
2.This kind of module is not supported, you may need plugins to support it
thread '
thread 'Parse `src/pages/User/Login/ResetPassword.tsx` failed.
 Error:   × 'const' declarations must be initialized
    ╭─[src/pages/User/Login/ResetPassword.tsx:19:1]
 16 │
 17 │ const loginUrl = '/user/login';
 18 │
 19 │ const ResetPassword: React.FC = () => {
    ·       ─────────────
 20 │   const navigate = useNavigate();
 21 │   const formRef = useRef<FormInstance>(null);
 22 │   const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
    ╰────
  × Expected a semicolon
    ╭─[src/pages/User/Login/ResetPassword.tsx:19:1]
 16 │
 17 │ const loginUrl = '/user/login';
 18 │
 19 │ const ResetPassword: React.FC = () => {
    ·                    ─
 20 │   const navigate = useNavigate();
 21 │   const formRef = useRef<FormInstance>(null);
 22 │   const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
    ╰────
  × Expected ',', got ':'
    ╭─[src/pages/User/Login/ResetPassword.tsx:44:1]
 41 │     }
 42 │   }, [loginConfig]);
 43 │
 44 │   const checkCaptchaError = (error: any) => {
    ·                                   ─
 45 │     doCaptchaError(error);
 46 │     formRef.current?.setFieldsValue({ ...formRef.current?.getFieldsValue(), captcha: '' });
 47 │   };
    ╰────

Potential Causes:
1.The module have syntax error.
2.This kind of module is not supported, you may need plugins to support it
<unnamed>' panicked at rust-plugins\strip\src\lib.rs<unnamed>:
112:thread '<unnamed>' panicked at rust-plugins\strip\src\lib.rs' panicked at library\core\src\panicking.rs::9:
215112::Parse src/layouts/layout.tsx failed. See error details above.59
:
:
Parse src/pages/User/Login/ResetPassword.tsx failed. See error details above.
panic in a function that cannot unwindstack backtrace:

note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'stack backtrace:
stack backtrace:
<unnamed>' panicked at library\core\src\panicking.rsnote: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
:thread caused non-unwinding panic. aborting.

farm.config.ts:

import { defineConfig } from '@farmfe/core';
import farmLessPlugin from '@farmfe/js-plugin-less';
import farmJsPluginSvgr from '@farmfe/js-plugin-svgr';
import strip from '@farmfe/plugin-strip';
import * as path from 'node:path';
import { TanStackRouterVite } from '@tanstack/router-plugin/vite';
import antdLess from './antd-less';

export default defineConfig({
  compilation: {
    input: {
      index: './src/index.html'
    },
    output: {
      path: 'dist',
      publicPath: '/',
      targetEnv: 'browser',
      filename: 'assets/[name].[hash].[ext]',
      assetsFilename: 'static/[resourceName].[ext]'
    },
    resolve: {
      alias: {
        "@/": path.join(process.cwd(), "src"),
      },
    },
    external: ["node:fs"],
    sourcemap: process.env.NODE_ENV === 'development' ? 'all' : false,
  },
  server: {
    port: 9000,
    proxy: {
      '/api/': {
        target: 'http://127.0.0.1:8081',
        changeOrigin: true,
        pathRewrite: { '^': '' },
      },
      '/system/': {
        target: 'http://127.0.0.1:8081',
        changeOrigin: true,
        pathRewrite: { '^': '' },
        on: {
          proxyReq: (proxyReq, req, res, options) => {
            if (req.headers?.accept?.startsWith('text/event-stream')) {
              res.setHeader('location', options.target! + req.url!);
            }
          },
        }
      },
    }
  },
  envDir: 'env',
  plugins: [
    [
      '@farmfe/plugin-react',
      {
        refresh: process.env.NODE_ENV === 'development',
        development: process.env.NODE_ENV === 'development',
        runtime: "automatic",
      }
    ],
    ['@farmfe/plugin-sass', {
      sourceMap: true, // bool
      sourceMapIncludeSources: true, // bool
      alertAscii: true, // bool
      alertColor: true, // bool
      charset: true, // bool
      quietDeps: true, // bool
      verbose: false, // bool
      style: 'expanded',// 'expanded' | 'compressed' // output code style
    }],
    farmLessPlugin({
      lessOptions: {
        modifyVars: antdLess.v5Vars,
      }
    }),
    farmJsPluginSvgr({
      svgrOptions: {
        // loadPaths: [path.resolve(process.cwd())],
      },
      filters: {
        resolvedPaths: ['src/.*/.*\\.svg$'],
      },
    }),
    process.env.NODE_ENV === 'production' ?
      strip({
        functions: ['console.*', 'assert.*'],
        labels: ['unittest']
      }) : undefined,
  ],
  vitePlugins: [
    TanStackRouterVite({
      target: 'react',
      routesDirectory: 'src/routes/',
      autoCodeSplitting: false,
    }),
  ]
});

src/index.tsx:

import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { HelmetProvider } from 'react-helmet-async';
import { ConfigProvider } from "antd";
import { ProConfigProvider } from "@ant-design/pro-components";
import { createHashHistory, createRouter, RouterProvider } from '@tanstack/react-router';
import './i18n';
import './initEnv';

// Import the generated route tree
import { routeTree } from '@/routeTree.gen'

const history = createHashHistory();
// Create a new router instance
const router = createRouter({ routeTree, history: history })

const container = document.getElementById('root') as HTMLElement;
const root = createRoot(container);

// Register the router instance for type safety
declare module '@tanstack/react-router' {
  interface Register {
    router: typeof router
  }
}

root.render(<StrictMode>
  <HelmetProvider>
    <ConfigProvider
      getTargetContainer={() => container || document.body}
    >
      <ProConfigProvider hashed={false}>
        <RouterProvider router={router} />
      </ProConfigProvider>
    </ConfigProvider>
  </HelmetProvider>
</StrictMode>);

src/routes/__root.tsx:

import { createRootRoute, HeadContent, Link, Outlet, Scripts } from '@tanstack/react-router'
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
import { Button, Result, Space } from "antd";
import { PageLoading } from "@ant-design/pro-components";

export const Route = createRootRoute({
  component: RootLayout,
  notFoundComponent: Root404,
  pendingComponent: RootPendingComponent,
  errorComponent: RootErrorComponent,
})

function RootLayout() {
  return <>
    <HeadContent />
    <Outlet />
    <Scripts />
    {process.env.NODE_ENV === 'development' && <TanStackRouterDevtools />}
  </>
}

function Root404() {
  return <Result
    status="404"
    title="404"
    subTitle="页面不存在"
    extra={<Link to={'/'}><Button type="primary">返回首页</Button></Link>}
  />
}

function RootPendingComponent() {
  return <PageLoading size="large" tip={'页面正在加载中,请稍候。。。'} delay={200}>
    <span />
  </PageLoading>
}

function RootErrorComponent(props: { error: any; reset: Function } & any) {
  const { error, reset } = props;
  console.log('RootErrorComponent', props)
  return <Result
    status="error"
    title={error.name}
    subTitle={<>
      <span>{error.message}</span>
      <pre style={{
        textAlign: "left",
        fontSize: '1em',
        border: '1px solid red',
        borderRadius: '.25rem',
        padding: '.3rem',
        color: 'red',
        overflow: 'auto',
      }}><code>{error.stack}</code></pre>
    </>}
    extra={<Space>
      <Link to={'/'}><Button type="primary">返回首页</Button></Link>
      <Button type="default" onClick={reset}>重置</Button>
    </Space>}
  />
}

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (24) x64 AMD Ryzen 9 3900XT 12-Core Processor
    Memory: 31.48 GB / 63.93 GB
  Binaries:
    Node: 22.11.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.9.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.15.4 - C:\Program Files\nodejs\pnpm.CMD
    bun: 1.1.0 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (136.0.3240.14), ChromiumDev (137.0.3255.0)
    Internet Explorer: 11.0.26100.1
  npmPackages:
    @farmfe/core: ^1.7.5 => 1.7.5

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions