William Neely
William Neely

Reputation: 2092

Json files not imported when using @nx/js:swc to build library

When I try to run code from a library that is built using @nx/js:swc and imports JSON files, I get "MODULE_NOT_FOUND" errors when running the code. The module it can't find is the JSON file. Searching the web says that this is because we need to pass --copy-files on the command line when building. I tried adding "copyFiles: true" to the options for the executor but that didn't work.

Upvotes: 0

Views: 51

Answers (1)

William Neely
William Neely

Reputation: 2092

Nx exposes the "copy files" capability in project.json via the "assets" option. You need to include the JSON files here in order for them to be copied.

"build": {
      "executor": "@nx/js:swc",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/libs/abc",
        "main": "libs/abc/src/index.ts",
        "tsConfig": "libs/abc/tsconfig.lib.json",
        "assets": ["libs/abc/*.md", "libs/abc/**/*.json"]
      }
    },

Upvotes: 0

Related Questions