Cant't build project due to Redis being imported on client?
Unanswered
Giant panda posted this in #help-forum
Giant pandaOP
EDIT: FIxed the issue! Fix below!❤️
Why is next during build thinking Redis is imported on the client?
I double checked all imports, only SSR pages that have server actions, the server actions import my redisClient instance. Why would it throw during build??
So strange...
Why is next during build thinking Redis is imported on the client?
I double checked all imports, only SSR pages that have server actions, the server actions import my redisClient instance. Why would it throw during build??
Creating an optimized production build ...
Failed to compile.
./node_modules/@redis/client/dist/lib/client/socket.js
Module not found: Can't resolve 'net'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/@redis/client/dist/lib/client/index.js
./node_modules/@redis/client/dist/index.js
./node_modules/redis/dist/index.js
./src/lib/redis/redis.ts
./src/repositories/post/_getPublicPosts.ts
./src/repositories/post/post.repository.ts
./src/services/post/_updatePostById.ts
./src/services/post/post.service.ts
./src/app/(app)/[locale]/(creator)/dashboard/community/[handle]/@post/post/page.tsxSo strange...
9 Replies
Horned oak gall
are you using any barrel files? it might be imported VIA another file
Giant pandaOP
Removed all barrel files due to bundle sizes! @Horned oak gall
It is working fine in dev!
Only during build s hits the fan
Only during build s hits the fan
Horned oak gall
any chance to look at the source code?
Giant pandaOP
'server only';
import {createClient, RedisClientType} from 'redis';
....
if (typeof window === 'undefined') {
redis = createClient({
password: process.env.REDIS_PW,
socket: {
host: process.env.REDIS_HOST,
port: parseInt(process.env.REDIS_PORT),
reconnectStrategy: function (times) {
console.log('Reconnecting Redis')
return false;
}
},
disableOfflineQueue: true,
});
}
export {redis, getKeyRedis, setKeyRedis, invalidateRedisPattern};
import {createClient, RedisClientType} from 'redis';
....
if (typeof window === 'undefined') {
redis = createClient({
password: process.env.REDIS_PW,
socket: {
host: process.env.REDIS_HOST,
port: parseInt(process.env.REDIS_PORT),
reconnectStrategy: function (times) {
console.log('Reconnecting Redis')
return false;
}
},
disableOfflineQueue: true,
});
}
export {redis, getKeyRedis, setKeyRedis, invalidateRedisPattern};
Zero google results that sound helpful
All client components marked with use client where server actions are begin used. All server actions that use functions that include redis are marked with use server.
All other functions in the backend marked with server only.
Giant pandaOP
--
Managed to solve the issue by removing node_modules....
Managed to solve the issue by removing node_modules....