Open JMLX42 opened 2 years ago
✅ Admin UI ready
wait - compiling /api/__keystone_api_build...
error - ../../../../usr/local/lib/node_modules/smartshape_license_nodejs/smartshape_license_nodejs.linux-x64-gnu.node
Module parse failed: Unexpected character '' (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
This is obviously an error thrown by Webpack. However, the import
statement is in one the schemas. So I fail to understand how/why Webpack is running on the backend code.
My guess is NextJS is bundling using Webpack.
In the .keystone/admin
folder generated for my project, I see a next.config.js
file. It is apparently loading the NextJS configuration created here:
Including the Webpack configuration:
And there is apparently no way to customize it.
Since Webpack will hijack any call to require()
, here is the workaround I found:
const { myNativeFunction } = eval('require')('/path/to/native/module');
Then the require()
in /path/to/native/module/index.js
work as expected.
Thanks for this. It's a bug. We'll look into it.
This worked for me when building a custom field using uploaded data.
// run EXIF analysis
const meta = await (await import(/* webpackIgnore: true */ "./extractMeta")).extractMeta(upload.createReadStream());
How to reproduce
Attempt to import a module that will load a
.node
native module.Expected behavior
The app builds and runs normally.
Actual behavior
Webpack complains there is no loader for the
.node
module:I did not find how to customize Webpack in the KeystoneJS documentation.