0

I get this error when i run npm run lint

'dw' is not defined while running lint
'request' is not defined while running lint

My code:

var currentHttpParameterMap = request.httpParameterMap;
var product =dw.catalog.ProductMgr.getProduct(CurrentHttpParameterMap.pid.stringValue);

I know why this error comes. It's because local machine doesn't know about dw variable. But it works perfectly on browser.

Any idea to solve this error.

  • Normally you should be able to add predefined global variable to your settings of your lint, so it will not throw an error. You just have to make sure that these variable you add are actually always available. Which should be the case with dw and request – empiric Feb 20 at 9:10
0

So the answer of my question was below:

Instead

var currentHttpParameterMap = request.httpParameterMap;
var product =dw.catalog.ProductMgr.getProduct(CurrentHttpParameterMap.pid.stringValue);

Use:

var currentHttpParameterMap = request.httpParameterMap;
var ProductMgr = require('dw/catalog/ProductMgr');

var product =ProductMgr.getProduct(CurrentHttpParameterMap.pid.stringValue);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.