Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

transpile node_modules on server side #26771

Closed
gaurav5430 opened this issue Jun 30, 2021 · 3 comments
Closed

transpile node_modules on server side #26771

gaurav5430 opened this issue Jun 30, 2021 · 3 comments
Labels
bug Issue was opened via the bug report template.

Comments

@gaurav5430
Copy link

gaurav5430 commented Jun 30, 2021

What version of Next.js are you using?

10.0.7

What version of Node.js are you using?

12.18.3

What browser are you using?

Chrome

What operating system are you using?

Mac

How are you deploying your application?

AWS

Describe the Bug

extending my babel.config.js with next/babel , and extending my webpack config to include a package from node_modules, does not transpile the package on the server side / node.

I see that there is a solution to use next-transpile-modules, but I am just not sure why the current setup would not work.
I use the setup in other browser only projects to transpile a particular node module through webpack / babel config.

Expected Behavior

I would expect the babel loader to correctly transpile the node_modules package for usage in server / node.js, since i am using next/babel

To Reproduce

// babel config.js

module.exports = {
  presets: [
    [
      'next/babel',
      {
        useBuiltIns: 'entry',
        corejs: '3',
      },
    ],
    '@babel/preset-typescript',
    '@babel/preset-react',
  ],
  plugins: [
    [
      'react-css-modules',
      {
        autoResolveMultipleImports: true,
        generateScopedName: '[name]__[local]__[hash:base64:5]',
        handleMissingStyleName: 'warn',
        webpackHotModuleReloading: true,
      },
    ],
    '@babel/plugin-syntax-dynamic-import',
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-proposal-object-rest-spread',
    '@babel/plugin-proposal-optional-chaining',
    '@babel/plugin-proposal-nullish-coalescing-operator',
  ],
};

custom webpack babel loader config:

rules: [
      {
        test: /\.(js|tsx)$/,
        include: [
          path.resolve(__dirname, 'node_modules/@packageToInclude/'),
          path.resolve(__dirname, '/src'),
        ],
        use: {
          loader: 'babel-loader',
        },
      },
...
...
@gaurav5430 gaurav5430 added the bug Issue was opened via the bug report template. label Jun 30, 2021
@jamsinclair
Copy link
Contributor

@gaurav5430 this is to be expected. You'll want to look into the third party library https://github.com/martpie/next-transpile-modules. Best of luck!

@gaurav5430
Copy link
Author

why is this expected?

i have been depending on that library till now, but due to recent changes it has become difficult for me to continue using that library

which is why I am just trying to understand why it can't work like the above config

@jamsinclair
Copy link
Contributor

I'm no Next.js expert 😅 , but it heavily configures the webpack config to help build the optimised bundles. You'll need to override or augment these existing configs to support your use case.

You can see that in the source code for the next-transpile-modules library.

Likely you'll need to make use of the internal next babel loader and play with the webpack externals config. Which will start to get quite hacky.

due to recent changes it has become difficult for me to continue using that library

The author seems to be doing great work, if you're having issues might be worth starting an issue there! 😸

@vercel vercel locked and limited conversation to collaborators Jul 1, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants