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]: babel相关api无法在ssr端运行 #5564

Open
aasychen opened this issue Mar 21, 2024 · 2 comments
Open

[Bug]: babel相关api无法在ssr端运行 #5564

aasychen opened this issue Mar 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@aasychen
Copy link

版本信息

System:
    OS: macOS 14.1.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 22.23 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 122.0.6261.129
    Safari: 17.1.2
  npmPackages:
    @modern-js/app-tools: 2.48.3 => 2.48.3 
    @modern-js/eslint-config: 2.48.3 => 2.48.3 
    @modern-js/runtime: 2.48.3 => 2.48.3 
    @modern-js/tsconfig: 2.48.3 => 2.48.3

问题详情

Web Server Error - Internal server error, error = Error: Cannot find module '@babel/parser'
at webpackMissingModule (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:56657:50)
at Module../src/babel.server.js (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:56657:138)
at webpack_require (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:64544:37)
at Module../src/routes/page.data.ts (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:46534:70)
at webpack_require (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:64544:37)
at Module../node_modules/.modern-js/main/route-server-loaders.js (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:46496:88)
at webpack_require (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:64544:37)
at Module../node_modules/.modern-js/main/server-loader-combined.js (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:46523:139)
at webpack_require (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:64544:37)
at /Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:64618:27
at Object. (/Volumes/works/tmp/modern-demo/dist/bundles/main-server-loaders.js:64620:3)
at Module._compile (node:internal/modules/cjs/loader:1254:14)

复现链接

https://github.com/aasychen/modern-demo.git

复现步骤

1.pnpm i @babel/parser 安装babel包
1.开启modern 配置 { server:{ ssr: true } }
2.使用babel相关api在服务端使用,babel被拦截,import parser from ’@babel/parser‘ parser为undefined

@aasychen aasychen added the bug Something isn't working label Mar 21, 2024
@yimingjfe
Copy link
Member

因为项目中没有安装 @babel/parser,我安装了最新版的 @babel/parser,@babel/parser 是没有 default export,你是不是需要使用 parse 函数?

@aasychen
Copy link
Author

因为项目中没有安装 @babel/parser,我安装了最新版的 @babel/parser,@babel/parser 是没有 default export,你是不是需要使用 parse 函数?

是的,我要在运行时使用babel相关工具库,所以我通过前端发送到字符串到都服务端解析。

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

No branches or pull requests

2 participants