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

Failed to resolve babel plugin/preset paths with pnpm #700

Closed
buffaybu opened this issue Nov 16, 2020 · 1 comment
Closed

Failed to resolve babel plugin/preset paths with pnpm #700

buffaybu opened this issue Nov 16, 2020 · 1 comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: rollup 🗞️ Issue is related to rollup bundler bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@buffaybu
Copy link

buffaybu commented Nov 16, 2020

Environment

  • Linaria version: 2.0.2
  • Bundler (+ version): Rollup 1.32.1
  • Node.js version: 14.15.0
  • OS: macOS 11.0.1

Description

When using pnpm as package manager and referencing another styled component in style, babel throws an error:

// .babelrc
{
  "presets": ["linaria/babel"]
}

// index.ts
import { styled } from 'linaria/react';
export const Foo = styled.div``;
export const Bar = styled.div`
  .${Foo} {
    color: red;
  }
`;
(babel plugin) Error: /path/to/project/src/index.tsx: An unexpected runtime error ocurred during dependencies evaluation: 
Error: Cannot find module '@babel/plugin-transform-runtime' from '/path/to/project'
    at Function.resolveSync [as sync] (/path/to/project/node_modules/.pnpm/resolve@1.19.0/node_modules/resolve/lib/sync.js:90:15)
    at resolveStandardizedName (/path/to/project/node_modules/.pnpm/@babel/core@7.12.3/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
    at resolvePlugin (/path/to/project/node_modules/.pnpm/@babel/core@7.12.3/node_modules/@babel/core/lib/config/files/plugins.js:54:10)
    at loadPlugin (/path/to/project/node_modules/.pnpm/@babel/core@7.12.3/node_modules/@babel/core/lib/config/files/plugins.js:62:20)
    at createDescriptor (/path/to/project/node_modules/.pnpm/@babel/core@7.12.3/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
    at /path/to/project/node_modules/.pnpm/@babel/core@7.12.3/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/path/to/project/node_modules/.pnpm/@babel/core@7.12.3/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPluginDescriptors (/path/to/project/node_modules/.pnpm/@babel/core@7.12.3/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
    at /path/to/project/node_modules/.pnpm/@babel/core@7.12.3/node_modules/@babel/core/lib/config/config-descriptors.js:63:53

It may happen when your code or third party module is invalid or uses identifiers not available in Node environment, eg. window. 
Note that line numbers in above stack trace will most likely not match, because Linaria needed to transform your code a bit.

Cannot find module '@babel/plugin-transform-runtime' from '/path/to/project'

@babel/plugin-transform-runtime is a dependency of Linaria but not the app so this error seems fair. Either providing a full path or changing dirname to Linaria's may fix the problem.

I tried to replace babel plugin/preset name string in node_modules/linaria/lib/babel/evaluators/shaker/index.js with the resolved path by require.resolve and it worked:

transformOptions.presets.unshift(['@babel/preset-env', ...]);
transformOptions.presets.unshift([require.resolve('../preeval'), options]);
transformOptions.plugins.unshift('transform-react-remove-prop-types');
transformOptions.plugins.unshift(['@babel/plugin-transform-runtime', ...]);
// =>
transformOptions.presets.unshift([require.resolve('@babel/preset-env'), ...]);
transformOptions.presets.unshift([require.resolve('../preeval'), options]);
transformOptions.plugins.unshift(require.resolve('babel-plugin-transform-react-remove-prop-types'));
transformOptions.plugins.unshift([require.resolve('@babel/plugin-transform-runtime'), ...]);

Reproducible Demo

https://github.com/buffaybu/linaria-resolve-demo

pnpm install
pnpm build
@buffaybu buffaybu added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Nov 16, 2020
@github-actions github-actions bot added bundler: rollup 🗞️ Issue is related to rollup bundler bundler: webpack 📦 Issue is related to webpack bundler and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Nov 16, 2020
@Anber
Copy link
Collaborator

Anber commented Dec 8, 2020

Probably fixed in 3.0.0-beta.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: rollup 🗞️ Issue is related to rollup bundler bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

No branches or pull requests

2 participants