Help with setting up edge-js inside a next.js project
Odisseuss opened this issue · comments
Hello!
I am trying to set up edge-js to use it inside a next.js project. I have cloned the edge-js-quick-start project, added a new c# file with the code i want to run and tested it from inside the edge-js-quick-start project. It worked out of the box.
Now, to make it work in next.js, this is what i did:
- Copied the QuickStart.Core and QuickStart.sln in a folder inside my next.js app
- Added EDGE_USE_CORECLR and EDGE_APP_ROOT env variables and set them up as follows:
process.env.EDGE_USE_CORECLR = "1";
process.env.EDGE_APP_ROOT = require("path").join(
__dirname,
"../../../.net/QuickStart/QuickStart.Core/bin/Debug/net7.0"
);
- Edited the next.config.mjs to update the webpack config as per the docs:
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
const newConfig = { ...config };
newConfig.externals = {
"edge-js": "commonjs2 edge-js",
};
newConfig.node = {
__dirname: true,
__filename: true,
};
return newConfig;
},
};
export default nextConfig;
- Used edge.func to load the dll and try to run the function.
This however results in the following error:
CoreClrEmbedding::Initialize - Failed to initialize CoreCLR, HRESULT: 0x80070057
⨯ TypeError: edge.initializeClrFunc is not a function
at Hero (./src/components/component/hero.tsx:15:27)
at stringify (<anonymous>)
Not sure what i can do from here. I am assuming there is something going on regarding how next.js bundles the code, since the quickstart example worked fine