-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
PGLite: 'import', and 'export' cannot be used outside of module code #65361
Comments
I found out nextjs is unable to resolve the location of Adding a loader that transpile the package its working for me /** @type {import('next').NextConfig} */
let nextConfig = {
images: {},
webpack: (config, options) => {
config.module.rules.push({
test: /\.+(js|jsx|mjs|ts|tsx)$/,
use: options.defaultLoaders.babel,
include: fileURLToPath(import.meta.resolve("@electric-sql/pglite")),
type: "javascript/auto",
});
if (!options.isServer) {
config.resolve.fallback = { fs: false, module: false, path: false };
}
return config;
},
transpilePackages: [],
}; |
I tried this and worked in dev but not building. same error. any ideas? |
@prananta I am able to fix the build error by adding these options to
Notes: If a similar error occurs, try removing the packages and add again |
Thanks @zelief! I noticed I only needed the It shows warning that this approach won't work in the next major version, but at least it works for now. |
For me what helped was adding it as part of the experimental serverComponentsExternalPackages ...
experimental: {
serverComponentsExternalPackages: ['@electric-sql/pglite'],
},
... |
Link to the code that reproduces this issue
https://github.com/Neo-Ciber94/pglite-next-bug
To Reproduce
@electric-sql/pglite
page.tsx
with this query, that just query the time:next.config
, the package usesfs
andmodule
import fornodejs
but those are not used on the client.npm run build
, you will recieve this error:Current vs. Expected behavior
It should just bundle the
@electric-sql/pglite
without problemsProvide environment information
Which area(s) are affected? (Select all that apply)
Module Resolution, Webpack
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
I used next
14.2.3
, the lib@electric-sql/pglite
only exportsesm
and is already minified.The text was updated successfully, but these errors were encountered: