Hi all I get the lintin…

3 minute read

Hi all. I get the linting error Imports of apps are forbidden when I try to import one library into another library.  The app is called myapp and the libraries are called myapp-feature-1 and myapp-data-access. The error occurs when library myapp-feature-1 tries to import myapp-data-access. Does anyone have any suggestions for how to fix this error?

Responses:

can you paste your tsconfig.json & tslint.json ?

tsconfig.json: { "compileOnSave": false, "compilerOptions": { "rootDir": ".", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "importHelpers": true, "target": "es5", "module": "esnext", "typeRoots": ["node_modules/@types"], "lib": ["es2017", "dom"], "skipLibCheck": true, "skipDefaultLibCheck": true, "baseUrl": ".", "paths": { "@ccp/myapp/feature-one": [ "libs/myapp/feature-one/src/index.ts" ], "@ccp/myapp/data-access": [ "libs/myapp/data-access/src/index.ts" ] } }, "exclude": ["node_modules", "tmp"] } tslint.json ```{ “rulesDirectory”: [“node_modules/@nrwl/workspace/src/tslint”], “rules”: { “arrow-return-shorthand”: true, “callable-types”: true, “class-name”: true, “deprecation”: { “severity”: “warn” }, “forin”: true, “import-blacklist”: [true, “rxjs/Rx”], “interface-over-type-literal”: true, “member-access”: false, “member-ordering”: [ true, { “order”: [ “static-field”, “instance-field”, “static-method”, “instance-method” ] } ], “no-arg”: true, “no-bitwise”: true, “no-console”: [true, “debug”, “info”, “time”, “timeEnd”, “trace”], “no-construct”: true, “no-debugger”: true, “no-duplicate-super”: true, “no-empty”: false, “no-empty-interface”: true, “no-eval”: true, “no-inferrable-types”: [true, “ignore-params”], “no-misused-new”: true, “no-non-null-assertion”: true, “no-shadowed-variable”: true, “no-string-literal”: false, “no-string-throw”: true, “no-switch-case-fall-through”: true, “no-unnecessary-initializer”: true, “no-unused-expression”: true, “no-var-keyword”: true, “object-literal-sort-keys”: false, “prefer-const”: true, “radix”: true, “triple-equals”: [true, “allow-null-check”], “unified-signatures”: true, “variable-name”: false,

"nx-enforce-module-boundaries": [
  true,
  {
    "enforceBuildableLibDependency": true,
    "allow": [],
    "depConstraints": [
      { "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] }
    ]
  }
]   } }```

sorry, the nx.json :sweat_smile:

Also, which version of Nx do you currently use?

haha, here’s nx.json , I’m running version 9.0.4.

{ "npmScope": "ccp", "implicitDependencies": { "workspace.json": "*", "package.json": "*", "tsconfig.json": "*", "tslint.json": "*", "nx.json": "*" }, "projects": { "myapp": { "tags": [] }, "myapp-e2e": { "tags": [], "implicitDependencies": ["myapp"] }, "myapp-feature-one": { "tags": [] }, "myapp-data-access": { "tags": [] } } }

Ok, just wanted to make sure you don’t have any tags/lint rules set up

Are you able to upgrade to the latest version?

Using npm run update or nx migrate?

Because we fixed a couple of issues related to linting

upgrading should be pretty straightforward

ok, let me give that a try

:+1:

the upgrade failed with error Schematic "update-9-1-0" not found in collection "@nrwl/workspace". .

Here’s the migrations.json file that was generated: { "migrations": [ { "version": "9.1.0-beta.1", "description": "Update prettier to 1.19.1 with support for typescript 3.7; Update eslint and tslint", "factory": "./src/migrations/update-9-1-0/update-9-1-0", "package": "@nrwl/workspace", "name": "update-9-1-0" }, { "version": "9.1.0-beta.1", "description": "Update eslint and tslint config to provide better IDE support", "factory": "./src/migrations/update-9-1-0/update-lint-config", "package": "@nrwl/workspace", "name": "update-lint-config-9-1-0" }, { "version": "9.2.0-beta.1", "description": "Add cacheable operations to nx.json", "factory": "./src/migrations/update-9-2-0/update-9-2-0", "package": "@nrwl/workspace", "name": "update-9-2-0" }, { "version": "9.2.0-beta.3", "description": "Update jest to v25", "factory": "./src/migrations/update-9-2-0/update-9-2-0", "package": "@nrwl/jest", "name": "update-9.2.0" }, { "version": "9.2.0-beta.1", "description": "Set buildLibsFromSource property to true to not break existing projects.", "factory": "./src/migrations/update-9-2-0/set-build-libs-from-source", "package": "@nrwl/web", "name": "set-build-libs-from-source" } ] }

Hmm…I suppose it is due to a missing npm install

so nx migrate works a bit differently than ng update

nx migrate is designed to work also in large monorepos, where the migration process might take longer & even span across multiple PRs (which is why we generate a migration.json)

so, when you run nx migrate, Nx analyzes ur workspace and updates the package.json

that allows you to inspect it and in case adjust if needed

The console log should also print some info, like to run “npm install” once ur ok with the package.json changes & then run nx migrate migration.json (or similar => check the console log) :slightly_smiling_face:

let me know if it works then

I see, makes sense. It mentions the need to do an npm i in the docs, I was just rushing through - sorry.

no worries :slightly_smiling_face:

upgrading fixed the linting error. Thank you!

awesome :+1:

+1 u now have the latest greatest as well :wink:

Updated: