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

[Bug] partialBundling causes an error in the build product #769

Closed
niuiic opened this issue Nov 22, 2023 · 18 comments · Fixed by #772
Closed

[Bug] partialBundling causes an error in the build product #769

niuiic opened this issue Nov 22, 2023 · 18 comments · Fixed by #772
Labels
bug Something isn't working

Comments

@niuiic
Copy link

niuiic commented Nov 22, 2023

Steps to reproduce

git clone https://github.com/niuiic/gallery
pnpm i
pnpm build --filter css-components
pnpm dev --filter website

Open the console.

The output:
image

In /home/niuiic/Documents/projects/gallery/apps/website/src/view/page/main/Main.tsx

import cssComponents from 'css-components'
console.log(cssComponents)

cssComponents is {}

In /home/niuiic/Documents/projects/gallery/packages/css/farm.config.build.ts
Unset partialBundling, then cssComponents is an array with one item.
enforceResources is set to [{ name: 'wavyUnderline', test: [ 'src/components/wavyUnderline/*' ] }].

import type { UserConfig } from '@farmfe/core'
import dts from '@farmfe/js-plugin-dts'
import { farmRawPlugin, farmSassPlugin } from 'farm-plugins'
import { readdirSync, statSync } from 'fs'
import { join } from 'path'

const chunks: {
  name: string
  test: string[]
}[] = []

const walkDir = (dirPath: string, cb: (filePath: string) => void) => {
  const items = readdirSync(dirPath)
  items.forEach((item) => {
    const itemPath = join(dirPath, item)
    const isDir = statSync(itemPath).isDirectory()
    if (isDir) {
      walkDir(itemPath, cb)
    } else {
      cb(itemPath)
    }
  })
}

const collectChunks = (filePath: string) => {
  if (!filePath.includes('index.ts')) {
    return
  }
  let matchedText = filePath.match(/\/src\/components\/([^\/]+)\/*/)
  if (matchedText) {
    chunks.push({
      name: matchedText[1],
      test: [`src/components/${matchedText[1]}/*`]
    })
  }
}

walkDir(join(process.cwd(), 'src/components'), collectChunks)

const config: UserConfig = {
  compilation: {
    input: {
      index: './src/index.ts'
    },
    output: {
      entryFilename: 'index.mjs',
      targetEnv: 'browser',
      format: 'esm'
    },
    resolve: {
      alias: {
        '@/': join(process.cwd(), 'src')
      }
    },
    minify: true,
    sourcemap: false,
    presetEnv: false,
    lazyCompilation: true
  },
  plugins: [
    farmSassPlugin(),
    farmRawPlugin(),
    dts({
      tsConfigPath: './tsconfig.json'
    })
  ]
}

export default config

What is expected?

The output
image

What is actually happening?

{}

System Info

System:
    OS: Linux 6.1 Gentoo Linux
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 12.92 GB / 15.59 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.1.0 - /run/user/1000/fnm_multishells/11955_1700613217468/bin/node
    npm: 10.2.0 - /run/user/1000/fnm_multishells/11955_1700613217468/bin/npm
    pnpm: 8.10.5 - /run/user/1000/fnm_multishells/11955_1700613217468/bin/pnpm
  npmPackages:
    @farmfe/core: ^0.14.3 => 0.14.3


### Any additional comments?

_No response_
@niuiic
Copy link
Author

niuiic commented Nov 22, 2023

In /home/niuiic/Documents/projects/gallery/packages/css/src/index.ts

import * as wavyUnderline from './components/wavyUnderline'

interface Component {
  css: string
  html: string
}

export default [wavyUnderline] as Component[]

@Nirvana-Jie Nirvana-Jie added the bug Something isn't working label Nov 22, 2023
@wre232114
Copy link
Member

use partialBundling.groups instead of enforceResources. enforceResources will ignore dynamic import contraints.

and test should be a regex, for example: src/components/wavyUnderline/.*

@niuiic
Copy link
Author

niuiic commented Nov 22, 2023

works

@niuiic niuiic closed this as completed Nov 22, 2023
@niuiic niuiic reopened this Nov 22, 2023
@niuiic
Copy link
Author

niuiic commented Nov 22, 2023

I made a mistake, it does not work. Setting groups does not split it into chunks.

set enforceResources
image

set groups
image

And there is no dynamic import.

Dynamic import is in src/main.ts which is not used when build.

@wre232114
Copy link
Member

try set partialBundling.targetMinSize to 0

@niuiic
Copy link
Author

niuiic commented Nov 22, 2023

Set groups and targetMinSize

farm-plugins:build: cache bypass, force executing 106922e0314b13a1
farm-plugins:build:
farm-plugins:build: > [email protected] build /home/niuiic/Documents/projects/gallery/packages/farm-plugins
farm-plugins:build: > farm build
farm-plugins:build:
farm-plugins:build: [ Farm ] Using config file at /home/niuiic/Documents/projects/gallery/packages/farm-plugins/farm.config.ts
farm-plugins:build: [ Farm ] ⚡️ Build completed in 32ms! Resources emitted to dist.
farm-plugins:build: [ FarmDtsPlugin ] ⚡️ Dts Plugin Build completed in 766ms! Resources emitted to dist.
farm-plugins:build: Failed to mark outputs as cached for farm-plugins#build: rpc error: code = Unavailable desc = cookie timeout expired
css-components:build: cache bypass, force executing 0697386bf6a25838
css-components:build:
css-components:build: > [email protected] build /home/niuiic/Documents/projects/gallery/packages/css
css-components:build: > farm build -c farm.config.build.ts
css-components:build:
css-components:build: [ Farm ] Using config file at /home/niuiic/Documents/projects/gallery/packages/css/farm.config.build.ts
css-components:build: file:https:///home/niuiic/Documents/projects/gallery/node_modules/.pnpm/@[email protected]/node_modules/@farmfe/core/dist/config/schema.js:264
css-components:build:         throw new Error(`${validationError}. \n Please check your configuration file or command line configuration.`);
css-components:build:               ^
css-components:build:
css-components:build: Error: Validation error: Number must be greater than 0 at "compilation.partialBundling.targetMinSize".
css-components:build:  Please check your configuration file or command line configuration.
css-components:build:     at parseUserConfig (file:https:///home/niuiic/Documents/projects/gallery/node_modules/.pnpm/@[email protected]/node_modules/@farmfe/core/dist/config/schema.js:264:15)
css-components:build:     at resolveUserConfig (file:https:///home/niuiic/Documents/projects/gallery/node_modules/.pnpm/@[email protected]/node_modules/@farmfe/core/dist/config/index.js:293:26)
css-components:build:     at async build (file:https:///home/niuiic/Documents/projects/gallery/node_modules/.pnpm/@[email protected]/node_modules/@farmfe/core/dist/index.js:49:24)
css-components:build:
css-components:build: Node.js v21.1.0
css-components:build:  ELIFECYCLE  Command failed with exit code 1.
css-components:build: ERROR: command finished with error: command (/home/niuiic/Documents/projects/gallery/packages/css) pnpm run build exited (1)
css-components#build: command (/home/niuiic/Documents/projects/gallery/packages/css) pnpm run build exited (1)

set enforceResources and targetMinSize

farm-plugins:build: cache bypass, force executing 106922e0314b13a1
farm-plugins:build:
farm-plugins:build: > [email protected] build /home/niuiic/Documents/projects/gallery/packages/farm-plugins
farm-plugins:build: > farm build
farm-plugins:build:
farm-plugins:build: [ Farm ] Using config file at /home/niuiic/Documents/projects/gallery/packages/farm-plugins/farm.config.ts
farm-plugins:build: [ Farm ] ⚡️ Build completed in 34ms! Resources emitted to dist.
farm-plugins:build: [ FarmDtsPlugin ] ⚡️ Dts Plugin Build completed in 744ms! Resources emitted to dist.
farm-plugins:build: Failed to mark outputs as cached for farm-plugins#build: rpc error: code = Unavailable desc = cookie timeout expired
css-components:build: cache bypass, force executing 3f5023f3be6a3a68
css-components:build:
css-components:build: > [email protected] build /home/niuiic/Documents/projects/gallery/packages/css
css-components:build: > farm build -c farm.config.build.ts
css-components:build:
css-components:build: [ Farm ] Using config file at /home/niuiic/Documents/projects/gallery/packages/css/farm.config.build.ts
css-components:build: file:https:///home/niuiic/Documents/projects/gallery/node_modules/.pnpm/@[email protected]/node_modules/@farmfe/core/dist/config/schema.js:264
css-components:build:         throw new Error(`${validationError}. \n Please check your configuration file or command line configuration.`);
css-components:build:               ^
css-components:build:
css-components:build: Error: Validation error: Number must be greater than 0 at "compilation.partialBundling.targetMinSize".
css-components:build:  Please check your configuration file or command line configuration.
css-components:build:     at parseUserConfig (file:https:///home/niuiic/Documents/projects/gallery/node_modules/.pnpm/@[email protected]/node_modules/@farmfe/core/dist/config/schema.js:264:15)
css-components:build:     at resolveUserConfig (file:https:///home/niuiic/Documents/projects/gallery/node_modules/.pnpm/@[email protected]/node_modules/@farmfe/core/dist/config/index.js:293:26)
css-components:build:     at async build (file:https:///home/niuiic/Documents/projects/gallery/node_modules/.pnpm/@[email protected]/node_modules/@farmfe/core/dist/index.js:49:24)
css-components:build:
css-components:build: Node.js v21.1.0
css-components:build:  ELIFECYCLE  Command failed with exit code 1.
css-components:build: ERROR: command finished with error: command (/home/niuiic/Documents/projects/gallery/packages/css) pnpm run build exited (1)
css-components#build: command (/home/niuiic/Documents/projects/gallery/packages/css) pnpm run build exited (1)

 Tasks:    1 successful, 2 total
Cached:    0 cached, 2 total
  Time:    3.367s
Failed:    css-components#build

 ERROR  run failed: command  exited (1)
 ELIFECYCLE  Command failed with exit code 1.

@wre232114
Copy link
Member

my mistake, you can set targetMinSize to 1, cause it can not be zero for now

@niuiic
Copy link
Author

niuiic commented Nov 22, 2023

Three components and three output files. This works. But it seems there is still something wrong with enforceResources.

image

Test should be correct now.

css-components:build: [
css-components:build:   {
css-components:build:     name: 'wavyUnderline',
css-components:build:     test: [ 'src/components/wavyUnderline/.*' ]
css-components:build:   }
css-components:build: ]

@wre232114
Copy link
Member

I'll check enforceResources, it should work too.

@niuiic
Copy link
Author

niuiic commented Nov 22, 2023

image

wavyUnderline/index.ts import raw string from wavyUnderline/wavyUnderline.html and wavyUnderline/wavyUnderline.scss, and then export these.

index.ts export all thing from wavyUnderline/index.ts.

No dynamic import.

@niuiic
Copy link
Author

niuiic commented Nov 22, 2023

Unfortunately, groups does not work either.

I forget to test the website.

image

@wre232114
Copy link
Member

This may be a issue related to bundling, I'll look into it

@wre232114
Copy link
Member

I found the reason, it will be fixed in 0.14.4

wre232114 added a commit that referenced this issue Nov 23, 2023
@niuiic
Copy link
Author

niuiic commented Nov 23, 2023

This is not fixed in 0.14.4.
image
@wre232114

@wre232114 wre232114 reopened this Nov 23, 2023
@wre232114
Copy link
Member

I'll try, it works with my examples

@wre232114
Copy link
Member

entryFilename: 'index.mjs' should be entryFilename: '[entryName].mjs'. index.mjs will overide all entries name including the farm runtime.

I'll make farm runtime not affect by this option in 0.14.5 too.

@wre232114
Copy link
Member

fixed in 0.14.5

@niuiic
Copy link
Author

niuiic commented Nov 24, 2023

This is fixed.

@niuiic niuiic closed this as completed Nov 24, 2023
@github-actions github-actions bot mentioned this issue Feb 6, 2024
This was referenced Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants