Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@babel/helper-module-imports is not listed in dependencies, fails to run with pnpm #155

Open
IlyaSemenov opened this issue Oct 4, 2018 · 6 comments

Comments

@IlyaSemenov
Copy link

IlyaSemenov commented Oct 4, 2018

@babel/helper-module-imports is directly used:

var addDefault = require('@babel/helper-module-imports').addDefault
but it's not listed in package dependencies. Because of that, the package fails to run in pnpm managed environment.

@babel/helper-module-imports must be moved from devDependencies to dependencies.

@IlyaSemenov
Copy link
Author

Same goes for @babel/plugin-syntax-jsx.

@LinusBorg
Copy link
Member

Does pnpm ignore devDependencies? Becuase they are listed there.

@IlyaSemenov
Copy link
Author

IlyaSemenov commented Oct 4, 2018

Of course it does, same as npm and yarn. devDependencies are only installed when you are developing the package (i.e. checkout it individually and run npm install in the library directory). If a package is listed as a dependency of some other package, its devDependencies are ignored.

With npm and yarn 'flattening' node_modules, the two unlisted packages are there by coincidence (pulled by some other related project module), so the mistake is not apparent. With npmp there is no flattening and the mistake becomes apparent.

@LinusBorg
Copy link
Member

LinusBorg commented Oct 4, 2018

If a package is listed as a dependency of some other package, its devDependencies are ignored.

That's not correct. These deps will only be ignored when you run npm --production.

See: https://docs.npmjs.com/cli/install

By default, npm install will install all modules listed as dependencies in package.json.

With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.

  • NOTE: The --production flag has no particular meaning when adding a dependency to a project.

Edit: However, I agree that it might still be better to list it under dependencies as in the context of this plugin, "using it in production" means "using it in a babel compile process".

But OTOH I feel like the dependencies/devDependencies difference is murky on th frontend. It makes much more sense for backend apps that generally don't have a build process involved, which kind of sits in between development and production, depending on how you look at it.

@IlyaSemenov
Copy link
Author

IlyaSemenov commented Oct 4, 2018

By default, npm install will install all modules listed as dependencies in package.json.

Correct. But this is not recursive.

So if a user checks out babel-plugin-transform-vue-jsx repository and runs npm install, @babel/helper-module-imports will be pulled. But if a user uses babel-plugin-transform-vue-jsx in his project (that is, lists babel-plugin-transform-vue-jsx in his own package.json), then npm install will not pull recursive (deep) devDependencies.

It's not specific to pnpm. After all, you can test that with plain npm. In an empty directory, run:

npm i babel-plugin-transform-vue-jsx
ls -l node_modules

you will see:

❯ ls -l node_modules
total 0
drwxr-xr-x  7 semenov  staff  224 Oct  4 21:38 babel-plugin-transform-vue-jsx
drwxr-xr-x  6 semenov  staff  192 Oct  4 21:38 esutils

The difference between dependencies/devDependencies is only murky in the final project. The distinction is however very clear in reusable libraries. dependencies are what is needed to use a library, and devDependencies are what is needed to build, test and publish it.

@decademoon
Copy link

I have the same issue with Yarn 2 PnP. I resolved it by adding to .yarnrc.yml the following and then running yarn install:

packageExtensions:
  babel-plugin-transform-vue-jsx@*:
    dependencies:
      "@babel/helper-module-imports": "*"

But this is really just a band-aid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants