farm-fe / farm

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

[Bug Report]: File not found, required dist/NestJs.mjs #1521

Closed blaicer15 closed 2 months ago

blaicer15 commented 3 months ago

Steps to reproduce

arn dev
yarn run v1.22.22 $ farmup -w [ Farmup ] Using config file at ~/backend-farm/farm.config.ts [ Farmup ] [entry: ./src/main.ts] [format: esm] [target: node] [ Farmup ] Build completed in 922ms ⚡️FULL EXTREME! Resources emitted to ./dist. [ Farmup:NestJs ] node:internal/modules/cjs/loader:1147 throw err; ^

Error: Cannot find module '~/backend-farm/dist/NestJs.mjs' at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15) at Module._load (node:internal/modules/cjs/loader:985:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'MODULE_NOT_FOUND', requireStack: [] }

Node.js v20.11.1

[ Farmup ] "NestJs" PID 22352 exit 1

Reproduce link

No response

What is actually happening?

Compilation fails, does not locate NestJs.mjs file

System Info

System:
    OS: Linux 5.15 Linux Mint 21.3 (Virginia)
    CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
    Memory: 2.65 GB / 7.71 GB
    Container: Yes
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.5.2 - ~/.nvm/versions/node/v20.11.1/bin/npm
    bun: 1.0.30 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 125.1.66.118
    Chrome: 126.0.6478.126
  npmPackages:
    @farmfe/core: ^1.2.4 => 1.2.6
ErKeLost commented 3 months ago

i'll check it

shulandmimi commented 3 months ago

could you provide me with the contents of the ~/backend-farm/dist/ directory and the contents of the ~/backend-farm/farm.config.ts file?

blaicer15 commented 3 months ago

Sure... the image of folder dist:

imagen

my file farm.config.ts:

import { defineConfig } from '@farmfe/core'; import NestPlugin from './index.plugin.ts';

export default defineConfig({ plugins: [NestPlugin()], });

ErKeLost commented 3 months ago

@blaicer15 Until this issue is resolved you can use @farmfe/core version 1.2.4 , to temporarily avoid this error

shulandmimi commented 3 months ago

@blaicer15 if you want to use the latest version, you can change index.plugin.ts to:

we will optimize templates and farmup later.

import { JsPlugin } from '@farmfe/core';

export default function NestPlugin(): JsPlugin {
  return {
    name: 'NestPlugin',
    config: (config) => {
      const mode =
        config.compilation.mode ?? process.env.NODE_ENV ?? 'development';
      const isDev = mode === 'development';
      const compilation = config.compilation ?? {};

      const script = compilation.script ?? ({} as any);
      return {
        compilation: {
          script: {
            plugins: script.plugins ?? [],
            target: script.target ?? 'es2019',
            parser: {
              tsConfig: {
                decorators: script.parser?.tsConfig?.decorators ?? true,
                dts: script.parser?.tsConfig?.dts ?? false,
                noEarlyErrors: script.parser?.tsConfig?.noEarlyErrors ?? false,
                tsx: script.parser?.tsConfig?.tsx ?? false,
              },
            },
            decorators: {
              legacyDecorator: script.decorators?.legacyDecorator ?? true,
              decoratorMetadata: script.decorators?.decoratorMetadata ?? true,
              decoratorVersion:
                script.decorators?.decoratorVersion ?? '2021-12',
              includes: [],
              excludes: ['node_modules/**/*'],
            },
          },
          presetEnv: compilation.presetEnv ?? !isDev,
          minify: compilation.minify ?? !isDev,
          output: {
            format: compilation.output?.format ?? 'esm',
            targetEnv: compilation.output?.targetEnv ?? 'node',
            entryFilename:
              compilation.output?.entryFilename ?? '[entryName].js',
            filename: compilation.output?.filename ?? '[name].[hash].mjs',
          },
        },
      };
    },
  };
}
ErKeLost commented 2 months ago

The nextjs project can run normally in version 1.3.0