Closed JRichens closed 5 months ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Maybe a bit late, does it work if you use import
instead of require
?
Example:
// src/app/page.tsx
import odbc from "odbc"
export default function Home() {
const connectionString = ''
const connection = await odbc.connect(connectionConfig)
const queryResult = await connection.query(`SELECT * from testtable`)
console.log({queryResult})
return <>Home Page - Check your server log</>
}
If this doesn't work, you could try to use a api route to fetch your data and use this api route then in your page to fetch the content.
Thanks for the reply. It doesn't work either way, no. I had to create an express node server with an API to it to work in the end. Would have been useful to work out the box in a NEXT.js server component though. Just couldn't figure out why it wouldn't!!
Hello, I tried using Next.JS API route, but got the following error:
./node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
<!doctype html> | |
Any ideas please?
The main problem is, that nextjs tries to bundle the odbc package.
I tried it quickly and was able to get it running by updating the next.config.mjs
to the following:
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ['odbc'],
},
};
export default nextConfig;
Doc ref: https://nextjs.org/docs/app/api-reference/next-config-js/serverComponentsExternalPackages
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
On a Windows 10 machine using Node v18.18.0 starting a fresh Next v13.5.2 project (blank) then installing odbc 2.4.8, my project starts fine as seen below.
However, in my page.tsx, when I simply start with
const odbc = require('odbc')
I get the following errors on my project.Would you please point out as to where I am going wrong?
Thank you