Announcement

Collapse
No announcement yet.

Using NPM for Custom Modules

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using NPM for Custom Modules

    Hope you guys are having a great end-of-year! I've got a question that I'm sure is a bonehead mistake I'm making, but here goes...

    We're creating a new module in our system and are looking to use some NPM or Yarn packages as a part of it.

    In the root of the module
    Code:
    (client/custom/modules/module-name)
    , we installed NPM and then installed the packages that we want to install.

    So far, so good.

    But then we went to import or require the library from
    Code:
    client/custom/modules/module-name/src/views/model/model-detail-view.js
    and no bueno.

    At first, we do a simple 'require' statement at the top of the file (before
    Code:
    `define(....`)
    and get a 404 error. File not found at client/src/{package}.

    So we then update the 'require' statement to
    Code:
    require("../../../custom/modules/module-name/node_modules/{package}")
    and get a 403 Forbidden.

    So, my question...what is the appropriate way to include an NPM package in a new/custom module?

    Does "import" work the same way?

    If we want to use ES6 classes, should require/import statements be in the class extension or before "define?"
Working...
X