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

feat: add ssrRequire in ssrloadmodule for #5424 #5425

Closed
wants to merge 10 commits into from

Conversation

zhangyuang
Copy link
Contributor

@zhangyuang zhangyuang commented Oct 26, 2021

Description

for #5424

require keywords is undefined when call ssrLoadmodule in entry-server file

Additional context

ssrModuleLoader function only inject NodeJs.Global in context but not NodeRequire which cause require is not defined error occur when evaluating !entry module. I can't determine whether vite do this on purpose. i think vite should support commonjs module syntax in nodejs environment because many old file code used it .

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • [ x] Read the Contributing Guidelines.
  • [x ] Read the Pull Request Guidelines and follow the Commit Convention.
  • [ x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • [ x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • [ x] Ideally, include relevant tests that fail without this PR but pass with it.

@zhangyuang zhangyuang changed the title fix: add global.require in ssrloadmodule fix: add global.require in ssrloadmodule for #5424 Oct 26, 2021
@zhangyuang
Copy link
Contributor Author

cc @patak-js @antfu

@Shinigami92 Shinigami92 added p3-minor-bug An edge case that only affects very specific usage (priority) feat: ssr labels Oct 26, 2021
@zhangyuang
Copy link
Contributor Author

zhangyuang commented Oct 26, 2021

In the latest code, i add a function ssrRequire which load bare module by nodeRequire function and load module in entry file use nodejs native require function.
please cc @Shinigami92

@zhangyuang zhangyuang changed the title fix: add global.require in ssrloadmodule for #5424 fix: add ssrRequire in ssrloadmodule for #5424 Oct 26, 2021
@zhangyuang
Copy link
Contributor Author

Maybe someone can follow up the pr? i am trying to add vite to transform server side code in my ssr framework replace webpack.i hope i can get more support @Shinigami92 @patak-js @antfu

@Shinigami92
Copy link
Member

@zhangyuang I'm not the right person for SSR 🙁 sorry, hope someone else can help you
I will try merge the newest main into this branch, so the new CI will trigger correctly and the old node v14 checks will go away.

@zhangyuang
Copy link
Contributor Author

zhangyuang commented Nov 1, 2021

thank you for response, i have succeed add vite in my ssr framework with npm link the change, i hope the changed code can be published in the official version

@Shinigami92
Copy link
Member

Is it possible to add a test to the playground?

@zhangyuang
Copy link
Contributor Author

ok, I was thinking exactly the same thing

@zhangyuang
Copy link
Contributor Author

I have supplemented some test code in ssr-vue example, please review when free time @Shinigami92

Shinigami92
Shinigami92 previously approved these changes Nov 1, 2021
@antfu antfu changed the title fix: add ssrRequire in ssrloadmodule for #5424 feat: add ssrRequire in ssrloadmodule for #5424 Nov 1, 2021
antfu
antfu previously approved these changes Nov 1, 2021
Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I will bring this to our team meeting and see if this is what we expect for Vite generally.

@zhangyuang zhangyuang dismissed stale reviews from antfu and Shinigami92 via 8c56f93 November 2, 2021 09:08
@zhangyuang
Copy link
Contributor Author

Is there any progress 😊 @antfu

Shinigami92
Shinigami92 previously approved these changes Nov 8, 2021
@Shinigami92
Copy link
Member

@zhangyuang last fridays meeting we were only 3 members (mostly conflict with new sommer-winter time change). So in worst case could be that you need to wait another 1.5 week from now for next meeting, sry

@zhangyuang
Copy link
Contributor Author

@zhangyuang last fridays meeting we were only 3 members (mostly conflict with new sommer-winter time change). So in worst case could be that you need to wait another 1.5 week from now for next meeting, sry

ok, take it easy,i am not hurried

@zhangyuang
Copy link
Contributor Author

Active it, is there any progress? @Shinigami92 @antfu

@Shinigami92
Copy link
Member

It's on p3 meeting notes 👍 Sadly Evan was not available last two meetings. Also seems that @antfu is very busy last days.
So sorry for that, but happens some times 🤷 Just be patient.

@zhangyuang
Copy link
Contributor Author

Is there any progress? The feature is important for me 😭

@yyx990803
Copy link
Member

Why is this important? What makes it absolutely necessary to use require() instead of import?

@zhangyuang
Copy link
Contributor Author

Why is this important? What makes it absolutely necessary to use require() instead of import?

For example, i have some old code like

const getConfig = () => require(resolve(process.cwd() ,'./config'))

that need to used in server-entry

@zhangyuang
Copy link
Contributor Author

Ref #5424

I will try use createRequire to use require syntax

@Shinigami92
Copy link
Member

[...] i have some old code [...]

Maybe this is a problem and you should try to rewrite it to use new code 🤔

@zhangyuang
Copy link
Contributor Author

zhangyuang commented Dec 3, 2021 via email

@patak-dev
Copy link
Member

Closing as #5424 has been closed. We are also planning to move to ESM by default in SSR, see #8150

@patak-dev patak-dev closed this May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(bug: ssr) NodeRequire is undefined when call ssrLoadmodule in entry-server file
5 participants