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

Module not found: Can't resolve '../build/Release/sqlserverv8' #310

Open
VittorioMorellini opened this issue Nov 16, 2023 · 10 comments
Open

Comments

@VittorioMorellini
Copy link

VittorioMorellini commented Nov 16, 2023

https://github.com/VittorioMorellini/portfolio14

This is my repo with msnodesqlv8 (4.1.1) and next 13.5.6
I am using node 18.18.2

I have this error in build, I am not able to understand, I used already this driver with Next.js 13 and I did not get errors.
Why is this error happening? There is no reason to happen.
The installation is going good, but the build is not working.
I have tried everything, delete node_modules and reinstall.
But the error still appears
I had prisma in this project before and I removed. This package for sql server does not compile

Vittorio Morellini

@TimelordUK
Copy link
Owner

#294

is it simiar to this

@TimelordUK
Copy link
Owner

https://github.com/eisberg-labs/nextjs-node-loader

does this help at all

@VittorioMorellini
Copy link
Author

https://github.com/eisberg-labs/nextjs-node-loader

does this help at all

Hi thank you, I install the package and add to my next.config this:

const nextConfig = {
experimental: {
serverActions: true
},
reactStrictMode: true,
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'raw.githubusercontent.com',
port: '',
pathname: '/VittorioMorellini/articles/main/images/**',
},
],
},
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;
},
}
module.exports = nextConfig

But I did not solve, do I have to install webpack? I did not add it, I did not use it
I am not able to solve yet

@TimelordUK
Copy link
Owner

TimelordUK commented Nov 16, 2023

for now can you try this

yarn add nextjs-node-loader --save-dev

edit node_modules/msnodesqlv8/lib/util.js and add .node on end

const utilModule = ((() => {
  const { QueryAggregator } = require('./query-aggregator')
  const { SchemaSplitter } = require('./shema-splitter')
  const cppDriver = require('../build/Release/sqlserverv8.node')

next.config.js

/** @type {import('next').NextConfig} */


module.exports = {
  experimental: {
    serverActions: true
  },
  reactStrictMode: true,
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'raw.githubusercontent.com',
        port: '',
        pathname: '/VittorioMorellini/articles/main/images/**',
      },
    ],
  },
  webpack: (config, options) => {
    // console.log('HERE WE ARE')
    config.module.rules.push({
      test: /\.node$/,
      use: [
        {
          loader: "nextjs-node-loader",
          options: {
            outputPath: config.output.path
          }
        },
      ],
    })
 
    return config
  }
}
yarn run v1.22.21
$ next dev
  ▲ Next.js 13.5.6
  - Local:        http://localhost:3000
  - Environments: .env.development
  - Experiments (use at your own risk):
     · serverActions

 ✓ Ready in 2.5s
 ○ Compiling /page ...
 ✓ Compiled /page in 4.1s (1511 modules)
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NO_SECRET]
https://next-auth.js.org/warnings#no_secret
{ session: null }
 ✓ Compiled in 1920ms (603 modules)
{ session: null }
 ✓ Compiled /api/auth/[...nextauth]/route in 200ms (913 modules)
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NO_SECRET]
https://next-auth.js.org/warnings#no_secret
Who am I?
I am a software engineer and I love web development.
I am not so young, unfortunately, I am a full stack developer because I don't want to leave nor backend neither frontend
I have worked as a software engineer for more than twenty years in product and consultancy companies.
I have the determination to be a reference as a Senior SDE on the Web

@VittorioMorellini
Copy link
Author

It worked with your suggestion,
Thank you for your suggestion. But if I have to edit the util.js it is not so smooth, it is not an optimized configuration.

Do I need webpack installed and a package? I think yes
Do you install webpack? I did it but maube it is not necessary

Thank you for your support

@TimelordUK
Copy link
Owner

yes i will have to release a patch to msnodesqlv8 but first i need to check it still works on linux and windows without nextjs
this can allow you to test for time being

@VittorioMorellini
Copy link
Author

Thank you, now I can continue to work.
What I did not understand is that I did not get this error on my project in production with next 13.4.12 or 13.5.6 using this driver.

I had in my portfolio with app dir, it is very starnge. I did not get.
Thank you for your support, it is wonderfull

@VittorioMorellini
Copy link
Author

You are incredible, support magic.
I used msnodesqlv8 in production with next.js 13.4.12 and 13.5.6 and I did not get the problem

With this next I started with next14 and I did not solve, it is strange. Even when I downgrade next.js I did not solve
Thank you for your suggestion

@VittorioMorellini
Copy link
Author

VittorioMorellini commented Nov 20, 2023

Hi msnodesqlv8,
with the new release of msnodesqlv8 4.1.2 I solved the compilation problem.
But I have a problem in runtime when a Open a page (every time the page change: detail of post, contacts with noquery).
This error happens in random pages, after a little navigation:

Unhandled Runtime Error
Error: nextjs-node-loader:
Error: Unable to initialize msnodesql

Call Stack
eval
node_modules\msnodesqlv8\build\Release\sqlserverv8.node (5:0)
(rsc)/./node_modules/msnodesqlv8/build/Release/sqlserverv8.node
file:///C:/PersonalProjects/Next/portfolio14.0/.next/server/vendor-chunks/msnodesqlv8.js (651:1)
__webpack_require__
file:///C:/PersonalProjects/Next/portfolio14.0/.next/server/webpack-runtime.js (33:43)
require
node_modules\msnodesqlv8\lib\util.js (4:20)
eval
node_modules\msnodesqlv8\lib\util.js (34:0)
(rsc)/./node_modules/msnodesqlv8/lib/util.js
file:///C:/PersonalProjects/Next/portfolio14.0/.next/server/vendor-chunks/msnodesqlv8.js (631:1)
__webpack_require__
file:///C:/PersonalProjects/Next/portfolio14.0/.next/server/webpack-runtime.js (33:43)
require
node_modules\msnodesqlv8\lib\table-column.js (4:19)

There is still something wrong, I did not realize what I am missing.
Do I miss webpack? do I miss gyp package?
What do I miss?

@TimelordUK
Copy link
Owner

https://github.com/TimelordUK/todo-with-nextjs_msnodesqlv8

can you try this very simple application - i changed a demo to simply use msnodesqlv8 it works without any of the above at all

if this works maybe can you use the same design,

I am sorry I do not have the time to dig into your specific application

see dbConnect.js

and the index.js, [id].js for usage

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - compiled client and server successfully in 203 ms (125 modules)
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
wait  - compiling / (client and server)...
event - compiled client and server successfully in 74 ms (163 modules)
wait  - compiling /api/task...
event - compiled client and server successfully in 62 ms (174 modules)
[index] opening connection
select * from Task
[ { id: 3, completed: 0, task: 'new task update', _id: 3 } ]
[index] closing connection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants