question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`no-unpublished-import`/`require` error importing devDependencies

See original GitHub issue

I have private project:

package.json (no files field and no .npmignore)

{
  "name": "private-project",
  "private": true,
  "dependencies": {
    "axios": "*"
  },
  "devDependencies": {
    "@babel/core": "*"
  }

When I load devDependencies, eslint throw an error:

index.js

import axios from 'axios';
import babel from '@babel/core'; // this throw an error: "@babel/core" is not published. eslint(node/no-unpublished-import)

// ...

with this following eslint configurations:

.eslintrc.js

module.export = {
  settings: {
    node: {
      allowModules: [],
      resolvePaths: [],
      tryExtensions: ['.js', '.json', '.node'],
    }
  },
  rules: {
    'node/no-unpublished-import': 'error',
    'node/no-unpublished-require': 'error',
  }
}

But if I move babel in dependencies, it does not throw an error

package.json

{
  "name": "private-project",
  "private": true,
  "dependencies": {
    "@babel/core": "*",
    "axios": "*"
  }

index.js

import axios from 'axios';
import babel from '@babel/core'; // this **does not** throw an error

// ...

Do I configure something wrong or is that expected behavior? Thanks.

More info: installed eslint version: 6.8.0 installed eslint-plugin-node version: 11.1.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
mysticateacommented, May 11, 2020

That’s the purpose of no-unpublished-import/require rule. We cannot import the devDependencies after publishing the package.

1reaction
ronkorvingcommented, May 28, 2020

Awesome, thanks for clarifying, @latipun7 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-node/no-unpublished-import.md at master - GitHub
This is similar to no-unpublished-require, but this rule handles import declarations. ... imports *unpublished* files or the packages of devDependencies .
Read more >
node/no-unpublished-import: "chai" is not published
The devDependencies option does not exist (anymore at leaast). If you want to allow imports from any package listed in your package.json, and ......
Read more >
Managing dependencies - The Go Programming Language
After your code imports the package, enable dependency tracking and get the ... If needed, it adds require directives to your go.mod file...
Read more >
package.json - npm Docs
This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just a...
Read more >
Inês Soares Silva (@inesoaresilva) / Twitter
#TIL how to allow imports from 'devDependencies'. In eslintrc file, add this rule: rules: { "node/no-unpublished-import": [ "error", { allowModules: [, ".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found