Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nextjs-node-loader

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nextjs-node-loader

Allows you to include native Node.js `.node` modules in your Next.js project

  • 1.1.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.8K
increased by5.12%
Maintainers
0
Weekly downloads
 
Created
Source

nextjs-node-loader (No Longer Maintained)

Status: Deprecated

There's no need for it anymore. I've added an example in next 14 to demo including different native modules. Solution in NextJS 14 is to add a:

experimental: {
  serverComponentsExternalPackages: ['yournativemodule'],
}

For a dependency built with neon bindings, you might also need to configure externals:

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ['mynativemodule'],
  },
  /** @type {import('webpack').Configuration} */
  webpack: (config, context) => {
    if (context.isServer) {
      config.externals = [
        ...config.externals,
        {'mynativemodule': 'commonjs mynativemodule'},
      ]
    }
    return config;
  },
};

A huge thank you to everyone who contributed to this project! ❤️

For historical purposes, the original README is preserved below.

nextjs-node-loader

This is a custom loader for Webpack that allows you to include native Node.js .node modules in your Next.js project. It simplifies the process of loading native modules by providing a standardized interface that works seamlessly with Next.js. This is a modified version of Node loader. More context on the why and example use of the loader in my blog post.

Getting Started

To begin, you'll need to install a nextjs-node-loader:

npm install nextjs-node-loader --save-dev

next.config.js

module.exports = {
  webpack: (config, { dev, isServer, webpack, nextRuntime }) => {
    config.module.rules.push({
      test: /\.node$/,
      use: [
        {
          loader: "nextjs-node-loader",
          options: {
            flags: os.constants.dlopen.RTLD_NOW,
            outputPath: config.output.path
          }
        },
      ],
    });
    return config;
  },
};

And use in e.g. your api route;

import module from "node-module";

export default function handler(req, res) {
  // ...
}

Options

NameTypeDefaultDescription
flags{Number}undefinedEnables/Disables url/image-set functions handling
outputPath{String}webpack's outputPathThe root path of shared node libraries
includeWebpackPublicPath{String}falseIf webpack_public_path should be included in a path for loading node module. For nextjs >13.2.5 should be false.

License

MIT

Keywords

FAQs

Package last updated on 22 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc