-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Labels
Description
Reproduction
- Run
npm install js-slang - Clone the
testInContextfunction from [here]()js-slang/src/utils/testing/index.ts
Line 58 in 02bf939
async function testInContext(code: string, rawOptions: TestOptions) {
const res = await testInContext("1+1;", {
chapter: Chapter.SOURCE_2
});
res.context.errors[0]
// -> TypeError: Cannot read properties of undefined (reading 'resolve')
// at defaultBundler (bundler.ts:46:39)
// at preprocessFileImports (index.ts:100:21)
// at async sourceFilesRunner (index.ts:115:28)
// at async runFilesInContext (index.ts:239:35)
// at async testInContext (workspace-context.ts:86:20)
// (the last line is my code, but copied from js-slang as mentioned above)Diagnosis
The error originates from bundler.ts:
path.resolve(...)In the browser, path is not defined, so path.resolve throws. The error ends up inside the context.
Solution
Polyfill path.
For Vite projects:
npm install path-browserifyIn vite.config.ts:
export default defineConfig({
plugins: [...],
resolve: {
alias: {
// point `path` imports to the browser shim
'path': 'path-browserify'
}
}
});