Skip to content
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

Error: strict mode: unknown keyword: "afterRequest" #335

Open
Harsh062 opened this issue Jan 10, 2024 · 2 comments
Open

Error: strict mode: unknown keyword: "afterRequest" #335

Harsh062 opened this issue Jan 10, 2024 · 2 comments

Comments

@Harsh062
Copy link

I am getting the below error when executing the basic example provided in the docs in my NodeJs project:

/Users/harsh/Desktop/http-snippet-demo/node_modules/ajv/dist/compile/index.js:120
        throw e;
        ^

Error: strict mode: unknown keyword: "afterRequest"
    at checkStrictMode (/Users/harsh/Desktop/http-snippet-demo/node_modules/ajv/dist/compile/util.js:174:15)
    at checkUnknownRules (/Users/harsh/Desktop/http-snippet-demo/node_modules/ajv/dist/compile/util.js:32:13)
    at checkKeywords (/Users/harsh/Desktop/http-snippet-demo/node_modules/ajv/dist/compile/validate/index.js:120:34)
    at validateFunctionCode (/Users/harsh/Desktop/http-snippet-demo/node_modules/ajv/dist/compile/validate/index.js:19:9)
    at Ajv.compileSchema (/Users/harsh/Desktop/http-snippet-demo/node_modules/ajv/dist/compile/index.js:80:45)
    at Ajv.resolveSchema (/Users/harsh/Desktop/http-snippet-demo/node_modules/ajv/dist/compile/index.js:193:23)
    at Ajv.getSchema (/Users/harsh/Desktop/http-snippet-demo/node_modules/ajv/dist/core.js:279:43)
    at validateHarRequest (/Users/harsh/Desktop/http-snippet-demo/node_modules/httpsnippet/dist/helpers/har-validator.js:66:24)
    at /Users/harsh/Desktop/http-snippet-demo/node_modules/httpsnippet/dist/httpsnippet.js:262:56
    at Array.forEach (<anonymous>)

Example Code:

const express = require('express');
const { HTTPSnippet } = require('httpsnippet');

const app = express();

const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'http://mockbin.com/request',
});

const options = { indent: '\t' };
const output = snippet.convert('shell', 'curl', options);
console.log(output);

const server = app.listen(8000, '0.0.0.0', () => {
  console.log('Example app listening at http://%s:%s', server.address().address, server.address().port);
});

httpsnippet version in package.json file: ^3.0.1
NodeJs version: 18.17

I am getting the same error via CLI as well when executing the below command:
httpsnippet example.json --target shell --client curl --output ./examples

@austineady
Copy link

Seeing the same issue with Node v20.10.0. Only reference to afterRequest I can find is within the har-schema package.

@mattvalleycodes
Copy link

mattvalleycodes commented Apr 10, 2024

@austineady @Harsh062 I believe you're getting this error because the version of the ajv you're using is 8 while version 6 is needed for httpsnippet. If you do downgrade to 6, the error should go away. Interestingly enough, ajv is not defined as dep for httpsnippet while it's been used. It's only defined as dependency within har-schema, and I' guessing ajv v8 has some breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants