SFCC's require doesn't work like Node. */ searches the cartridge path of the current site, ~/ stays in the current cartridge and module.superModule reaches the next copy of the same file. Intellij SFCC resolves these paths the way the server does, so completion, Go to Declaration and types land on the file the storefront would load
require targets, module.superModule, form links and Search Everywhere results follow the cartridge path of the site picked in the status bar, so they land on the file the server would loadRequire paths
| Path | Resolves to | Example |
|---|---|---|
dw/... | A Script API class, see API & Types | require('dw/catalog/ProductMgr') |
./..., ../... | A file relative to the current file | require('./helpers/cartHelpers') |
~/... | A file in the current cartridge | require('~/cartridge/scripts/helpers/basketHelpers') |
*/... | The first cartridge on the site's cartridge path that has the file | require('*/cartridge/scripts/helpers/productHelpers') |
<cartridge>/... | A file in the named cartridge | require('app_storefront_base/cartridge/controllers/Cart') |
| A bare name | A B2C module or a package in the global modules folder | require('server') |
require loads .js, .ds and .json files, so completion offers all three and leaves the extension out when you accept one, the same way the server looks them up
Complete paths
require paths complete from every linked cartridge. Each item shows the cartridge that owns it; the list opens with Ctrl+SpaceStart typing inside require('') and press Ctrl+Space:
- An empty or one-word path lists your linked cartridges, marked Cartridge, and the B2C modules and global modules you can require by name
- After
*/,~/,./or a cartridge name, completion walks the folders and files below it - Each item shows the cartridge or module that owns it, so you can tell
app_customfromapp_storefront_basebefore you accept
Only linked cartridges and modules are offered. Link a missing one in Cartridges & Modules
Go to the file the server loads
Cmd+Click or Cmd+B (Ctrl+Click or Ctrl+B) on a require path opens its target. A */ path usually exists in several cartridges, and what you get depends on the site scope:
| Scope | Targets |
|---|---|
| A site, for example RefArch | Only the cartridges on that site's path, in path order. The first one is the file the server loads |
| Global scope | Every linked cartridge that has the file. The IDE asks you to pick one |
Pick the site you are working on in the status bar to make navigation match the storefront
module.superModule
module.superModule is the module that the current file overrides: the same path in a cartridge further right on the cartridge path. It is how SFRA overrides extend the original instead of copying it
'use strict';
var base = module.superModule;
function getBadge(product) {
return product.custom.badgeText || null;
}
base.getBadge = getBadge;
module.exports = base;With a site scope selected, superModule resolves to the same file in the cartridges to the right of the current one on that site's path. In Global scope it resolves to the copies in your linked cartridges, with app_storefront_base first. Either way, base. completes the functions the original exports, and Cmd+Click on superModule opens the original
Controllers use the same mechanism with server.extend(module.superModule), then server.append, server.prepend and server.replace complete the routes of the original controller, see SFCC Contracts. Overrides creates both kinds of file for you
B2C modules and global modules
A bare require('server') doesn't point into a cartridge. On the server it loads a top-level folder next to your cartridges or a package in the special modules folder. In the IDE these come from the roots you mark yourself:
| Root | Mark it with | Then |
|---|---|---|
| B2C Module Root | Mark Directory as › B2C Module Root | Its scripts complete by module name, with the module icon |
| Modules (Global Modules) Root | Mark Directory as › Modules (Global Modules) Root | Its packages complete by name, for example server from SFRA's modules/server |
See Cartridges & Modules for the rules
Troubleshooting
| Symptom | What to do |
|---|---|
A */ path opens the wrong cartridge | Select the site in the site scope widget. In Global scope every copy is a target |
require('server') is unresolved | Mark SFRA's modules folder as Modules (Global Modules) Root |
| A cartridge is missing from completion | It is not linked. Link it in Cartridges & Modules |
module.superModule resolves to nothing | No other linked cartridge has a file at the same path below cartridge/, or the current cartridge is last on the site's path |
| A site's path names a cartridge that isn't in the project | Files in a cartridge that isn't linked can't be resolved. Add its source to the project and link it |