WASM-BIND库和开玩笑:无效或意外令牌 @import&quot?

发布于 2025-02-07 07:51:14 字数 1077 浏览 4 评论 0原文

我正在尝试在导入Rust/WASM库的React-Typecript项目中使用Jest,而在运行前端时它可以使用,但Jest测试失败了:

/workspace/react-jest-rust/node_modules/rust-wasm-lib/index.js:73
export function message(s) {
^^^^^^
SyntaxError: Unexpected token 'export'

我创建了一个示例,只需运行>克隆后的纱线测试a https://github.com/github.com/findetton/findetton/reaeact--reaect--react--react--开玩笑

我尝试配置开玩笑。如果我将其添加到package.json:

  "jest": {
    "transformIgnorePatterns": [
      "node_modules/(?!rust-wasm-lib)/"
    ]
  }

然后在运行纱线测试时会遇到其他错误:

/big/workspace/sequent/react-jest-rust/node_modules/rust-wasm-lib/index.js:125
    input = new URL('index_bg.wasm', import.meta.url);
                                            ^^^^

SyntaxError: Cannot use 'import.meta' outside a module

  2 | import logo from './logo.svg';
  3 | import './App.css';
> 4 | import init, {test} from 'rust-wasm-lib';
    | ^

I'm trying to use jest in a react-typescript project that imports a rust/wasm library and while it works when I run the front-end, the jest test fails with:

/workspace/react-jest-rust/node_modules/rust-wasm-lib/index.js:73
export function message(s) {
^^^^^^
SyntaxError: Unexpected token 'export'

I've created an example, just run yarn test a after cloning: https://github.com/Findeton/react-jest-rust

I've tried configuring jest. If I add this to package.json:

  "jest": {
    "transformIgnorePatterns": [
      "node_modules/(?!rust-wasm-lib)/"
    ]
  }

Then I get this other error when running yarn test a:

/big/workspace/sequent/react-jest-rust/node_modules/rust-wasm-lib/index.js:125
    input = new URL('index_bg.wasm', import.meta.url);
                                            ^^^^

SyntaxError: Cannot use 'import.meta' outside a module

  2 | import logo from './logo.svg';
  3 | import './App.css';
> 4 | import init, {test} from 'rust-wasm-lib';
    | ^

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文