I'm using nextjs version 13.5.6, node version 21.5.0, and npm version 10.2.4. I'm trying to add Grafana logging to a nextjs app router project using react 3 next starter (I'm using this next.config.js). To do this, I installed the winston-loki npm package. With the config linked above, the build didn't even complete (there was a module parse error on a snappy .node module). After adding the node loader to the webpack config part of the next config js, the build succeeded, the logging works, but I get the following warning (I get about 50 of these for each snappy OS support package):
./node_modules/snappy/index.js
Module not found: Can't resolve '@napi-rs/snappy-linux-arm-gnueabihf' in '/home/hunor/root/projects/project_brickedUp/project-minifig/node_modules/snappy'
Import trace for requested module:
./node_modules/snappy/index.js
./node_modules/winston-loki/src/batcher.js
./node_modules/winston-loki/index.js
...
Here's what the webpack part of the next config js looks like after adding the node loader:
webpack(config, { isServer }) {
if (!isServer) {
// We're in the browser build, so we can safely exclude the sharp module
config.externals.push('sharp')
}
// audio support
config.module.rules.push({
test: /.(ogg|mp3|wav|mpe?g)$/i,
exclude: config.exclude,
use: [
{
loader: require.resolve('url-loader'),
options: {
limit: config.inlineImageLimit,
fallback: require.resolve('file-loader'),
publicPath: ${config.assetPrefix}/_next/static/images/,
outputPath: ${isServer ? '../' : ''}static/images/,
name: '[name]-[hash].[ext]',
esModule: config.esModule || false,
},
},
],
})
// shader support
config.module.rules.push({
test: /.(glsl|vs|fs|vert|frag)$/,
exclude: /node_modules/,
use: ['raw-loader', 'glslify-loader'],
})
// This is what I added to original next config
config.module.rules.push({
test: /.node$/,
use: [
{
loader: 'nextjs-node-loader',
options: {
flags: os.constants.dlopen.RTLD_NOW,
outputPath: config.output.path,
},
},
],
})
return config
},
I've tried downgrading winston-loki, winston, npm, and node (each time I deleted the package-lock.json, node_modules, and .next), but the warnings persisted.
I'm thinking this has something to do with snappy being OS specific (in my node_modules, @napi-rs folder has the correct packages), but I don't quite understand what is happening in the background and why the irrelevant napi-rs/snappy packages are not ignored/why the project is looking for them.
Should these be resolved and if so, how can I do that?
I appreciate the help in advance, and let me know if more information needs to be provided.