Intellij IDEA 2025.2.2 - httpClient - trying to import modues

已回答

Under documentation from httpClient:

https://www.jetbrains.com/help/idea/2025.1/http-client-in-product-code-editor.html#using-response-handler-scripts

It states you can import scripts

 

sample.rest

###
# @name sample script
# @no-log
# @no-redirect
< {%
  import * as gen from '../../../../../httpRequests/scripts/gen';

  const body = {
    id: gen.generateId(),
  };

  request.variables.set('body', body)
%}
POST {{apiRoot}}/api/v1/?debug={{debug}}
Content-Type: application/json

{{body}}

 

gen.js

import * as lodash from 'lodash';

export function generateId() {
  console.log('crosses fingers', lodash.random())
  return 'XYZ';
}

 

but when i try to import lodash or fakerjs (which already in my project, loaded in node_modules folder), i am receiving errors:

Attempt 1

import lodash from 'lodash'

Results

 `Syntax error: cannot find file for module 'lodash'`

Attempt 2

import * as lodash from ‘../../../node_modules/lodash/lodash.js’

Results:  

no error from import, however when i try to use to use it:

`TypeError: Cannot find default value for object. (<HTTP Client handler stdlib>#151)`

 

So, just wondering if there is anything i can do to enable import from node_modules 

0

Also, would like to add, i am aware httpClient has ability to use {{$random.uuid}} variables, but I am trying to migrate a library of existing home grown http scripts using faker into using httpClient scripts.

0

Hello roy rico. Thanks for reaching out.

We’ve checked this and found that the HTTP Client currently doesn’t support importing from node_modules.
There’s already a feature request open for this functionality. You can go ahead and upvote it so that our developers can consider implementing the feature in the future.

0

请先登录再写评论。