Comments (8)
Have you tried without installing coffee-script
and setting ignoreWarnings[].message = /Can't resolve 'coffee-script'/
in the webpack config?
from vm2.
@XmiliaH I updated the config to be:
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
return {
...config,
ignoreWarnings: [/Can't resolve 'coffee-script'/],
};
},
};
module.exports = nextConfig;
And now I'm getting the error:
- warn ./node_modules/vm2/lib/resolver-compat.js
Critical dependency: the request of a dependency is an expression
Import trace for requested module:
./node_modules/vm2/lib/resolver-compat.js
./node_modules/vm2/lib/nodevm.js
./node_modules/vm2/lib/main.js
./node_modules/vm2/index.js
./app/api/script/route.ts
from vm2.
Then try to add the additional module.parser.javascript.commonjsMagicComments=true
.
from vm2.
Updated config:
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
return {
...config,
ignore warnings: [/Can't resolve 'coffee-script'/],
module: {
...config.module,
parser: {
...config.module.parser,
javascript: {
...config.module.parser.javascript,
commonjsMagicComments: true,
},
},
},
};
},
};
module.exports = nextConfig;
The warning is gone but when I access the route, I get a 404 error. To be sure it is not being caused by nonrelatedvm2
code, I removed it, and I can confirm the API route works normally. So, looks like for some reason, NextJS is not being able to compile the dependencies correctly.
The route code:
import { NextResponse } from "next/server";
import { NodeVM } from "vm2";
export async function GET() {
console.log("Enter");
const vm = new NodeVM({
timeout: 500,
sandbox: {},
});
console.log("Starting");
const result = vm.run(`return { a: "Bruno: }`);
console.log("Result");
return NextResponse.json({ data: result });
}
The logs:
- wait compiling /api/script/route (client and server)...
- event compiled client and server successfully in 1066 ms (395 modules)
- wait compiling /_error (client and server)...
Unfortunately, looks like there is no debug
mode for next dev
command.
from vm2.
The code that I used to test if it was related to vm2
or not.
import { NextResponse } from "next/server";
import { NodeVM } from "vm2";
export async function GET() {
console.log("Enter");
console.log("Starting");
console.log("Result");
return NextResponse.json({ data: "a" });
}
The logs:
- event compiled successfully in 242 ms (89 modules)
Enter
Starting
Result
from vm2.
While I cannot tell you why it does not work now. You could try a try-catch block and log the exception.
And some notes: NodeVM
does not have a timeout
option and the return
in the sandbox script will not be used.
from vm2.
Even with try-catch
there is no error available.
import { NextResponse } from "next/server";
import { VM } from "vm2";
export async function GET() {
try {
console.log("Enter");
const vm = new VM({
timeout: 500,
sandbox: {},
});
console.log("Starting");
const result = vm.run(`return { a: "Bruno: }`);
console.log("Result");
return NextResponse.json({ data: result });
} catch (error) {
console.error(error);
}
}
I really appreciate your help on this but looks like NextJS is missing something. Ty.
from vm2.
Closing this for now since NextJS does not provide any helpful information on what is causing the error.
from vm2.
Related Issues (20)
- freeze doesn't work on Array methods (shift, pop, etc) HOT 4
- fetch not available in vm2 with node 19 HOT 1
- VM and NodeVM behaves differently on await HOT 3
- Any tips for improving performance of `vm.run()`? HOT 9
- [VM2 Sandbox Escape] Vulnerability in [email protected] HOT 13
- Sandbox Escape in [email protected] HOT 3
- Adding a Security Policy HOT 1
- Modules not loading any more? HOT 16
- Overriding functions of objects from sandbox parameter inside NodeVM HOT 3
- Accessing .buffer property on a Float32Array HOT 8
- Lib memory leak HOT 8
- Hello, is there any way to make the large functions in node equal to those in VM2? Or not isolate large functions? HOT 16
- this.pathResolve is not a function in 3.9.18 HOT 2
- Work in a bundle HOT 3
- Use external modules without filesystem access HOT 1
- Typescript Set transpilation issues
- Node's test runner not available as builtin
- Isolating Imported Modules
- Discontinued HOT 63
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vm2.