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

Plugin not found if not under cwd #9273

Open
vbraun opened this Issue Jan 3, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@vbraun
Copy link

vbraun commented Jan 3, 2019

Bug Report

Current Behavior

I've installed babel in a separate directory /tools, which is not where my project lives. Trying to run babel fails with

$ /tools/babel source.ts 
{ Error: Cannot find module '@babel/plugin-proposal-class-properties' from '/my/project'
    at Function.module.exports [as sync] (/tools/lib/node_modules/@babel/core/node_modules/resolve/lib/sync.js:58:15)
    at resolveStandardizedName (/tools/lib/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
    at resolvePlugin (/tools/lib/node_modules/@babel/core/lib/config/files/plugins.js:54:10)
    at loadPlugin (/tools/lib/node_modules/@babel/core/lib/config/files/plugins.js:62:20)
    at createDescriptor (/tools/lib/node_modules/@babel/core/lib/config/config-descriptors.js:155:9)
    at items.map (/tools/lib/node_modules/@babel/core/lib/config/config-descriptors.js:110:50)
    at Array.map (<anonymous>)
    at createDescriptors (/tools/lib/node_modules/@babel/core/lib/config/config-descriptors.js:110:29)
    at createPluginDescriptors (/tools/lib/node_modules/@babel/core/lib/config/config-descriptors.js:106:10)
    at plugins (/tools/lib/node_modules/@babel/core/lib/config/config-descriptors.js:41:19) code: 'MODULE_NOT_FOUND' }

Expected behavior/code

Babel should just load the plugins from where babel is installed, and not override the module resolution base dir with cwd. I don't understand why you would want that, ever. If there is a use case (is there?) then at least catch and try again without overriding the base dir.

Babel Configuration (.babelrc, package.json, cli command)

My .babelrc is just

{
    "presets": [
        "@babel/env",
        "@babel/preset-typescript"
    ],
    "plugins": [
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-object-rest-spread"
    ]
}

and all required packages are installed under /tools

Environment

  • Babel version(s): 7.2.0
  • Node/npm version: Node v10.12.0, npm 6.4.1
  • OS: Fedora 29 x86_64
  • How you are using Babel: cli

Possible Solution

Plugins load fine if, in resolveStandardizedName, I replace

        resolve.sync(name, { basedir: dirname });

with

        resolve.sync(name);

Note that dirname is set to cwd (as absolute path), and there does not seem to be a way to override it from .babelrc.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Jan 3, 2019

Hey @vbraun! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@chenhaihong

This comment has been minimized.

Copy link

chenhaihong commented Jan 22, 2019

Is there any way to edit or override the default cwd? Maybe an option in webpack.config,js?
I read the code, but i can not find any way to edit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment