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

Use stricter imports to satisfy webpack 5 #9601

Closed

Conversation

daniel-ac-martin
Copy link

I run my server-side code through Webpack, in addition to my client-side code. As a part of my attempt to upgrade from Webpack v4 to v5, I have run into a problem whereby these require statements are no longer transformed by Webpack and so my application is broken. (Perhaps this is because the files are otherwise in an ESM style and Webpack v5 is being stricter than v4? Then again, this could just be a quirk in my set-up. - Has anyone else run into these problems?)

Note: I don't know if this solution is acceptable, as you may have had the require inline for a reason. (To avoid importing it when it isn't going to be overridden by the consumer?) There may also be a way to make Webpack v5 accept the code as it is. I've asked for guidance from the Webpack community here: webpack/webpack#15670

Please accept my apologies if I'm being silly.

Webpack v5 seems to no longer accept inline `require`'s in these files.
(Perhaps because they are otherwise in ESM style?)
@apollo-cla
Copy link

@daniel-ac-martin: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@daniel-ac-martin
Copy link
Author

daniel-ac-martin commented Apr 16, 2022

Adding the following rule to the webpack v5 config, avoids the need for this change:

{
    [...]
    module: {
      rules: [
        {
          test: /\.js$/,
          include: /node_modules/,
          type: 'javascript/auto'
        },
        [...]
      ]
    }
}

i.e. Setting the type to javascript/auto, whereas it would have been under, the more strict, javascript/esm.

It would be nice to avoid this workaround, if possible. I'm not sure if there's anything that can be done in @apollo/client to encourage the file to be processed correctly.

I was also wondering if this 'mixed syntax' file is really the correct thing to be published. - Perhaps the 'ssr' code should have its own .tsconfig that compiles to CommonJS modules?

@jpvajda jpvajda added 🏓 awaiting-contributor-response requires input from a contributor 🏓 awaiting-team-response requires input from the apollo team and removed 🏓 awaiting-contributor-response requires input from a contributor labels May 3, 2022
@hwillson
Copy link
Member

Thanks for this @daniel-ac-martin and sorry for the delay. Yes those inline requires are there for a reason, which you can read about here: apollographql/react-apollo#2627

That being said, we're exploring a new approach for this in #9975 (more changes coming there shortly).

@hwillson hwillson closed this Aug 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🏓 awaiting-team-response requires input from the apollo team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants