将Solidjs与包裹& @suid/材料构建失败

发布于 2025-02-02 02:46:40 字数 767 浏览 3 评论 0 原文

我尝试使用 solidjs +包裹+模板启动器项目: https://github.com/tiagocavalcante/solidts-parcel--

@suid/材料,例如按钮,构建失败。

以下是重现的方法:

  1. 查看项目模板从关于about URL。
  2. npm i -save @suid/材料
  3. 将以下内容放在 index.tsx 中:
import { render } from "solid-js/web";
import SuidButton from '@suid/material/Button'

function App() {
    return <>
    <SuidButton>Testing</SuidButton>
    </>;
}

render(App, document.getElementById("app")!);

您将获得错误输出:


              

I've tried to use the SolidJS+Parcel+TypeScript template starter project from here:
https://github.com/TiagoCavalcante/solidts-parcel

And once I import any element from @suid/material, such as Button, build fails.

Here's how to reproduce:

  1. Checkout project template from the about URL.
  2. npm i --save @suid/material
  3. Put the following in index.tsx:
import { render } from "solid-js/web";
import SuidButton from '@suid/material/Button'

function App() {
    return <>
    <SuidButton>Testing</SuidButton>
    </>;
}

render(App, document.getElementById("app")!);

You will get an error output:

???? Build failed.

@parcel/transformer-js: Expected ',', got 'ownerState'

  C:\Users\alona\dev\parcel\node_modules\@suid\material\Button\Button.jsx:307:25
    306 |     const contextProps = useContext(ButtonGroupContext);
  > 307 | Root ownerState={allProps} className={clsx(classes.root, otherProps.className, contextProps.className)} disabled={props.disabled} focusRipp
  >     |      ^^^^^^^^^^
    308 |       <Show when={!!props.startIcon}>
    309 |         <ButtonStartIcon className={classes.startIcon} ownerState={allProps}>

My question is, how can I make it play well with @suid/material?
it works fine when using ViteJS instead of Parcel

This issue seems related:
https://github.com/parcel-bundler/parcel/issues/6176
I asked on their discord, and apparently Parcel doesn't really support non-standard JS syntax in node_modules (like Typescript or JSX).

This means, that @suid/material cannot be used with Parcel, as well as others such as https://github.com/LXSMNSYC/solid-headless

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稚然 2025-02-09 02:46:40

没有官方支持的包裹模板,但您不需要一个。

这是一个基本设置,它使用打字稿并支持热模块更换。我没有对@suid/材料进行测试,但是在您添加必要的依赖项之后,它应该有效。

  1. 安装 babel-preset-solid @babel/core

包裹会自动拾取Babel配置,但最好坚持使用基于JSON的配置。由于包裹提供了自己的替代方案,因此无需 Babel-Transform-runtime Preset-env

包裹都支持两个项目宽的配置文件,例如babel.config.json,以及文件相对配置,例如.babelrc。

注意:应避免使用JavaScript Babel Configs(例如Babel.config.js)。这些导致包裹的缓存效率较低,这意味着每次重新启动包裹时,所有JS文件都会重新编译。
https://parceljs.org/languages/javascript/javascript/#babel

  1. 使用以下内容:
{
  "presets": ["solid"]
}
  1. 添加打字稿文件:
{
  "compilerOptions": {
    "jsx": "preserve",
    "jsxImportSource": "solid-js",
    "noEmit": true
  }
}
  1. 如果愿意,请添加热模块更换(HMR)支持。这是添加人力资源管理的一种非常粗略的方法,它可以按预期加载模块,但不幸的是没有保留状态:
import { render } from 'solid-js/web';
import { App } from './App';
const dispose = render(() => <App />, document.body);

if (module.hot) {
  module.hot.accept();
  module.hot.dispose(dispose);
}

我知道的一个小问题是Parceljs尚不支持有条件的出口,这使得Parceljs加载了SolidJ的生产而不是Solidjs,而不是它的发展建设。 https://github.com/solidjs/solidjs/solid-solid-refresh#other-dev-photh-dev----------------------------------------------------------------------------------------------------------------- dev--dother-dev--dev---the服务器

这不是包裹部分的缺点,而是由于Nodejs对某些常见兼容性问题的任意解决方案而引起的问题,该解决方案可以用插件解决。

您可以检查内容和文件结构的链接: htttps://stackover.com/a/a/a/75641238/7134134/7134134

There is no officially supported parcel template but you don't need one.

Here is a basic setup that uses typescript and supports Hot Module Replacement. I did not tested for @suid/material but with it should work after you add necessary dependencies.

  1. Install babel-preset-solid and @babel/core.

Parcel automatically picks up babel configuration but it is best to stick to the json based configuration. There is no need for babel-transform-runtime and preset-env since parcel provides its own alternatives:

Parcel supports both project wide config files such as babel.config.json, as well as file relative configs such as .babelrc.

Note: JavaScript Babel configs (e.g. babel.config.js) should be avoided. These cause Parcel’s caching to be less effective, which means all of your JS files will be recompiled each time you restart Parcel.
https://parceljs.org/languages/javascript/#babel

  1. Create a .babelrc file with the following content:
{
  "presets": ["solid"]
}
  1. Add typescript file:
{
  "compilerOptions": {
    "jsx": "preserve",
    "jsxImportSource": "solid-js",
    "noEmit": true
  }
}
  1. Add hot module replacement (HMR) support if you like. This is a very crude way to add HRM and it loads module as expected but unfortanetly does not preserve the state:
import { render } from 'solid-js/web';
import { App } from './App';
const dispose = render(() => <App />, document.body);

if (module.hot) {
  module.hot.accept();
  module.hot.dispose(dispose);
}

One minor issue I know of is ParcelJS doesn't support conditional exports yet, which makes ParcelJS load the production build of SolidJS instead of its development build. https://github.com/solidjs/solid-refresh#other-dev-servers

This is not a shortcoming on Parcel's part but an issue due to NodeJS's arbitrary solutions to some common compatibility problems, which can be solved with a plugin.

You can check the link for contents and file structures: https://stackoverflow.com/a/75641238/7134134

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文