Linaria: Problem with babel-plugin-module-resolver ("[linaria] failed to add dependency")

Created on 2 Mar 2019  路  4Comments  路  Source: callstack/linaria

Do you want to request a feature or report a bug?
bug

What is the current behavior?

File structure:

  • src

    • styles

    • colors.js

    • index.js

    • index.js

Using linaria together with babel-plugin-module-resolver (check module-resolver settings below), running the following code:

import { css } from 'linaria';

import { BLUE } from 'styles/colors';
// import { BLUE } from './colors';

export const globalCss = css`
    :global() {
        body {
            width: 100vw;
            height: 100vh;

            display: flex;
            justify-content: center;
            align-items: center;

            background-color: ${BLUE};
            color: olive;
        }
    }
`;

throws the following message:
[linaria] failed to add dependency for: styles/colors

along with some details ending with

missing:
   [ '.../linaria-module-resolver-bug/src/styles/node_modules',
     '.../linaria-module-resolver-bug/src/node_modules',
     '.../linaria-module-resolver-bug/node_modules/styles/colors',
     '.../linaria-module-resolver-bug/node_modules/styles/colors.js',
     '.../linaria-module-resolver-bug/node_modules/styles/colors.jsx',
     '.../linaria-module-resolver-bug/node_modules/styles/colors.ts',
     '.../linaria-module-resolver-bug/node_modules/styles/colors.tsx',
     '.../linaria-module-resolver-bug/node_modules/styles/colors.json',
     '.../node_modules',
     ...]

If I comment row 3 and uncomment row 4 everything works as it should.

The project still compiles and is able to run, but I of course wonder if everything is running as it should + an overflow in the log.

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

Instructions in the repo:
https://github.com/SchlagerKhan/linaria-module-resolver-bug

What is the expected behavior?

Compiling as should and not showing any errors,

Please provide your exact Babel configuration and mention your Linaria, Node, Yarn/npm version and operating system.
Yarn: 1.13.0
Node: 11.8.0

Babel config (also in the repository):

module.exports = {
    presets: [
        '@babel/preset-env',
        '@babel/preset-react',
        'linaria/babel',
    ],
    plugins: [
        [
            'module-resolver',
            {
                alias: {
                    'styles': './src/styles',
                },
            },
        ],
    ],
};
bug 馃悰

Most helpful comment

When we fail to add a dependency, the issue you'll have is that if you edit colors.js, it won't rebuild the css if you didn't edit the file with the CSS.

The warning is because we collect the list of dependencies before we transpile the code: https://github.com/callstack/linaria/blob/master/src/babel/evaluate.js#L111, so we don't have the rewritten paths from the babel plugin yet. We should fix it :)

All 4 comments

When we fail to add a dependency, the issue you'll have is that if you edit colors.js, it won't rebuild the css if you didn't edit the file with the CSS.

The warning is because we collect the list of dependencies before we transpile the code: https://github.com/callstack/linaria/blob/master/src/babel/evaluate.js#L111, so we don't have the rewritten paths from the babel plugin yet. We should fix it :)

Thanks for your quick response!

I'll filter out the warnings and minimize the resolver usage for now.

A few follow-up questions just to get a timeline perspective:

  • Is this a difficult fix?
  • Is there a new roadmap for coming linaria releases?
  • Is there anything I can do?

Not difficult, just needs to be done. I'll do it when I have some time this week.

Fantastic! Great library by the way with a lot of potential. Keep up the good work!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hotell picture Hotell  路  5Comments

amankkg picture amankkg  路  4Comments

zaguiini picture zaguiini  路  5Comments

secretlifeof picture secretlifeof  路  6Comments

braco picture braco  路  3Comments