Comments (24)
Thanks for reporting issues. I'll make it less strict today and release @farmfe/[email protected]
. For earlier versions, you can use html tags as placeholders like:
<div id="root">
<div>app-html-to-replace</div>
</div>
from farm.
It's limited by SWC, you may have to use other placeholders like <meta head />
, <meta styles />
in <head>
.
from farm.
I see, I'll try pepka if I can
from farm.
I browsered code of fela-vue, it contains both import and dynamic import under dist/bundle.mjs. that's the cause of this issue. I also reproduced the error locally, I fixed this error and added a test case
from farm.
Wow, I've completely forgotten that it's there under runtime compression part! Will review it - maybe, there are better ways to achieve the same now. But this helped as a test π
from farm.
please try @farmfe/[email protected]
from farm.
> npm i @farmfe/[email protected]
added 1 package, removed 1 package, changed 1 package, and audited 806 packages in 10s
190 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
> npm run d-dev
> [email protected] d-dev
> farm start ./d-c ./.../farm.config.ts
[ Farm ] Using config file at C:\Users\...farm.config.ts
[ Farm ] Port 9000 is in use, trying another one...
[ Farm ] Port 9001 is in use, trying another one...
[ building ] β transform (15) ../node_modules/@farmfe/runtime-plugin-hmr/src/overlay.ts.farm-runtime [ Farm ] Failed to start the server: Error: Parse `index.html` failed.
Error: Parse `index.html` failed.
Error:
Γ Stray end tag "head"
ββ[index.html:4:1]
4 β <meta charset="utf-8" />
5 β {head}
6 β {styles}
7 β </head>
Β· βββββββ
8 β <body>
9 β <div id="app">{ssr}</div>
9 β <script type="module" src="./src/main.ts"></script>
β°ββββ
Γ Start tag "body" seen but an element of the same type was already open
ββ[index.html:5:1]
5 β {head}
6 β {styles}
7 β </head>
8 β <body>
Β· ββββββ
9 β <div id="app">{ssr}</div>
10 β <script type="module" src="./src/main.ts"></script>
10 β </body>
β°ββββ
from farm.
It works in our example: https://github.com/farm-fe/farm/blob/main/examples/react-ssr/index.html#L10
from farm.
It works in our example: https://github.com/farm-fe/farm/blob/main/examples/react-ssr/index.html#L10
Yep, but not in <head>
from farm.
So sad. Thank you anyway, - I'll try.
from farm.
I've tried to workaround this by using the plugin system to avoid changing backend logic, but got an error.
I want to transform it to meta stuff you've suggested, then in the very end reverse those.
What I do:
plugins: [
{
name: '[clean html templating before]',
priority: 200,
transform: {
filters: { sources: [/^.*\.html$/], moduleTypes: ['html'] },
executor: async (param) => {
const {content} = param
if(content) param.content = getTmpl(content)({
head: '<meta head />',
styles: '<meta head />',
ssr: '<meta ssr />'
})
return param
}
}
},
{ // No error without this plugin.
name: '[clean html templating after]',
transformHtml: {
executor: ({htmlResource}) => {
htmlResource.bytes = [...Buffer.from(
Buffer.from(htmlResource as any)
.toString()
.replace(/<meta (\w+?) \/>/g, '{$1}')
)]
return htmlResource
}
}
}
]
What I get using almost the sample code https://www.farmfe.org/docs/api/js-plugin-api#transformhtml :
with backtrace full
[ Farm ] Port 9000 is in use, trying another one...
[ building ] β render index_a27d
thread '<unnamed>' panicked at crates\node\src\plugin_adapters\js_plugin_adapter\thread_safe_js_plugin_hook.rs:186:34:
called `Result::unwrap()` on an `Err` value: Error { status: InvalidArg, reason: "", maybe_raw: 0x0 }
stack backtrace:
0: 0x7fff1d8f20c5 - napi_register_module_v1
1: 0x7fff1d3e2f0d - <unknown>
2: 0x7fff1d8d7fe1 - napi_register_module_v1
3: 0x7fff1d8f450a - napi_register_module_v1
4: 0x7fff1d8f3e6f - napi_register_module_v1
5: 0x7fff1d8f4c01 - napi_register_module_v1
6: 0x7fff1d8f4725 - napi_register_module_v1
7: 0x7fff1d8f4669 - napi_register_module_v1
8: 0x7fff1d8f4654 - napi_register_module_v1
9: 0x7fff1e133807 - wasmer_vm_imported_memory32_atomic_notify
10: 0x7fff1e133db3 - wasmer_vm_imported_memory32_atomic_notify
11: 0x7fff1d68b908 - farm_swc_transform_react
12: 0x7fff1d692577 - farm_swc_transform_react
13: 0x7ff707dcdc27 - node_module_register
14: 0x7ff707dcd55d - node_module_register
15: 0x7ff707e89d1b - uv_update_time
16: 0x7ff707e89854 - uv_run
17: 0x7ff707e5ad52 - node::SpinEventLoop
18: 0x7ff707d44513 - ENGINE_get_load_privkey_function
19: 0x7ff707dd890d - node::Start
20: 0x7ff707dd79d7 - node::Start
21: 0x7ff707b6d8ac - AES_cbc_encrypt
22: 0x7ff709218238 - inflateValidate
23: 0x7fffacc87344 - BaseThreadInitThunk
24: 0x7ffface426b1 - RtlUserThreadStart
from farm.
make transformIndex
async:
transformHtml: {
executor: async ({htmlResource}) => {}
}
The docs needs to be updated
from farm.
from farm.
I tested that this should work:
[
{
name: 'test-transform-html-pre',
transformHtml: {
order: 0, // 0 means call this hook before parse and generate resources
executor: async ({ htmlResource }) => {
const code = Buffer.from(htmlResource.bytes as any).toString();
calledHooks.push('transformHtmlPre');
const replacedCode = code
.replace('{head}', '<meta head />')
.replace('{style}', '<meta style />')
.replace('{ssr}', '<meta ssr />');
return {
...htmlResource,
bytes: [...Buffer.from(replacedCode)]
};
}
}
},
{
name: 'test-transform-html-post',
transformHtml: {
order: 2, // 2 means call this hook after parse and generate resources
executor: async ({ htmlResource }) => {
calledHooks.push('transformHtmlPost');
const replacedCode = Buffer.from(htmlResource.bytes as any)
.toString()
.replace(/<meta (\w+?)>/g, '{$1}');
htmlResource.bytes = [...Buffer.from(replacedCode)];
return htmlResource;
}
}
}
]
from farm.
Yep. I've rewritten it to match codestyle and removed calledHooks tracing. It compiles, but breaks the runtime: it throws, telling, that one of my library functions is not a function. It should be interesting in the compiler perspective and to improve docs, but I'd rather stick with <meta />
stuff, 'cause it now looks more safe π Here's code btw:
plugins: [
{
name: '[test-transform-html-pre]',
transformHtml: {
order: 0, // 0 means call this hook before parse and generate resources
executor: async ({ htmlResource }) => {
htmlResource.bytes = [...Buffer.from(Buffer
.from(htmlResource.bytes as any)
.toString()
.replace('{head}', '<meta head />')
.replace('{styles}', '<meta style />')
.replace('{ssr}', '<meta ssr />')
)]
return htmlResource
}
}
},
{
name: '[test-transform-html-post]',
transformHtml: {
order: 2, // 2 means call this hook after parse and generate resources
executor: async ({ htmlResource }) => {
htmlResource.bytes = [...Buffer.from(Buffer
.from(htmlResource.bytes as any)
.toString()
.replace(/<meta (\w+?) \/>/g, '{$1}')
)]
return htmlResource
}
}
}
]
from farm.
It compiles, but breaks the runtime: it throws, telling, that one of my library functions is not a function.
Could you please provide more info about the runtime error
from farm.
It compiles, but breaks the runtime: it throws, telling, that one of my library functions is not a function.
Could you please provide more info about the runtime error
it's from fela-vue precompressed library that uses pepka
latest version.
The line from stack trace highlighted by blue.
And then it traces up to the application code.
And no such error with vite or without the transformations.
Just in case, the error look in chrome:
UPD: Seems that it has imported the whole lib as a plain object (I've breakpointed that):
from farm.
I can not reproduce the runtime error of fela-vue. could you provide a repo that can reproduce this error
from farm.
I can not reproduce the runtime error of fela-vue. could you provide a repo that can reproduce this error
No, - it's a relatively large monorepo. I can cut it from there, but not very soon. Have you tried using complement
function directly from pepka ?
from farm.
I think it's a issue related to lazy compilation(a guess based on the images above), i want to known is there a import('fela-vue')
or import('pepka')
in the project, so I can figure out what causes the error.
You can set lazyCompilation
to false
in farm.config.ts to see if the error solved.
from farm.
fixed in #1175 and will be released in @farmfe/[email protected]
from farm.
fixed in #1175 and will be released in
@farmfe/[email protected]
Nope, that's not that issue. Still there. Also, there's only one place where I use dynamic import, is to import icons.
Maybe you can put in App.vue (root vue component) this part of code to reproduce:
<template>
<div :class="f('flex actions')">
qwe
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { css, Renderer } from 'fela-vue'
import { qmergeDeep } from "pepka"
import { styl } from '@/styles'
const common = css`
.common-class {
color magenta
}
`
const felaOptions= {
defStyles: () => qmergeDeep(common, css`
.flex {display flex}
`),
preset: { unit: ['rem', {}] },
modifiers: { m: false },
ssr: true
}
const renderer = new Renderer(felaOptions)
const styl = renderer.styl
const f = computed(() => styl(css`
.actions {
gap 2
margin-top 2
> *:not(:first-of-type) { margin-left 2 }
@media (max-width: 1050px) { margin-top 1.25 }
}
`))
</script>
from farm.
upd: I was able to upgrade only to ver18. Therefore will try again with ver19 and report here.
from farm.
Yep! Looks like it works!
from farm.
Related Issues (20)
- [Bug Report]: caceh error
- Support object external like `Record<string, string>`
- [Bug Report]: Panic caused by repeated builds
- Install `@tanstack/react-query` and build error HOT 2
- refactor: Embroidered `create-farm`
- [Feature Request]: Support `vite-plugin-vue-devtools`
- [Bug Report]: Duplicate define of `import.meta.env`
- [Feature Request]: custom CSS transformer support HOT 1
- [Bug Report]: ιθΏθζ¬θΏθ‘εΊη°ιθ―― HOT 2
- [Bug Report]: Css inconsistency between development and production
- Optimize record_manager
- [Feature Request]: css modules support `auto` like it in css-loader HOT 4
- [Bug Report]: ε¦ζηΌθ―ζΆεε¨publicδΈι’ index.html δΌηΌθ―ζ₯ι HOT 1
- [Bug Report]: δ½Ώη¨ vite-plugin-node-polyfills ε―Όθ΄ηηΌθ―ε¨ζ₯ι
- Optimize core default config options
- [Feature Request]: Support middleware mode
- [Feature Request]: ζ―ζViteζδ»ΆRemix HOT 1
- [Bug Report]: build error HOT 4
- [Bug Report]: Input matching is not perfect enough
- [Bug Report]: Failed to run nestjs project
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from farm.