Navigation Menu

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

CSS imports from node package fail on build, work on develop due to ~ confusion #5758

Closed
crucialfelix opened this issue Jun 6, 2018 · 8 comments
Labels
help wanted Issue with a clear description that the community can help with. stale? Issue that may be closed soon due to the original author not responding any more. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@crucialfelix
Copy link

Description

CSS imports from a node package work in develop, but fail in build.

CSS imports in The Wacky World of Webpack are supposed to use a tilde: ~package.

gatsby develop does NOT find the file if there is a tilde.

gatsby build does NOT find the file is there ISN'T a tilde.

Steps to reproduce

layouts/index.js

import './layout.css';

layout.css

@import "purecss/build/pure.css";

/* @import "~purecss/build/pure.css";  */

/* this local file is never included even in develop ! */
@import "./colors.scss"; 

But that local file does work if included on layouts/index.js

gatsby develop

This works for the no-tilde imports.

gatsby build

This works only for the tilde imports.

Expected result

Builds

Actual result

build failure:

success Building CSS — 2.193 s

error Generating JavaScript bundles failed


  Error: ./made/default/src/layouts/layout.css
  Module build failed: ModuleNotFoundError: Module not found: Error: Cannot resolve 'file' or 'directory' ./purecss/build/pure.css in /Users/crucialfelix/code/matterminds/made/default/src/layouts
      at /Users/crucialfelix/code/matterminds/node_modules/webpack/lib/Compilation.js:229:38
      at onDoneResolving (/Users/crucialfelix/code/matterminds/node_modules/webpack/lib/NormalModuleFactory.js:29  :20)
      at /Users/crucialfelix/code/matterminds/node_modules/webpack/lib/NormalModuleFactory.js:85:20
      at /Users/crucialfelix/code/matterminds/node_modules/webpack/node_modules/async/lib/async.js:726:13
      at /Users/crucialfelix/code/matterminds/node_modules/webpack/node_modules/async/lib/async.js:52:16
      at done (/Users/crucialfelix/code/matterminds/node_modules/webpack/node_modules/async/lib/async.js:241:17)
      at /Users/crucialfelix/code/matterminds/node_modules/webpack/node_modules/async/lib/async.js:44:16
      at /Users/crucialfelix/code/matterminds/node_modules/webpack/node_modules/async/lib/async.js:723:17
      at /Users/crucialfelix/code/matterminds/node_modules/webpack/node_modules/async/lib/async.js:167:37
      at /Users/crucialfelix/code/matterminds/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
      at onResolved (/Users/crucialfelix/code/matterminds/node_modules/enhanced-resolve/lib/Resolver.js:38:18)
      at /Users/crucialfelix/code/matterminds/node_modules/enhanced-resolve/lib/Resolver.js:127:10
      at /Users/crucialfelix/code/matterminds/node_modules/enhanced-resolve/lib/Resolver.js:191:15
      at applyPluginsParallelBailResult.createInnerCallback.log (/Users/crucialfelix/code/matterminds/node_module  s/enhanced-resolve/lib/Resolver.js:110:4)
      at loggingCallbackWrapper (/Users/crucialfelix/code/matterminds/node_modules/enhanced-resolve/lib/createInn  erCallback.js:21:19)
      at /Users/crucialfelix/code/matterminds/node_modules/tapable/lib/Tapable.js:134:6
      at Resolver.<anonymous> (/Users/crucialfelix/code/matterminds/node_modules/enhanced-resolve/lib/DirectoryDe  scriptionFilePlugin.js:24:12)
      at Storage.finished (/Users/crucialfelix/code/matterminds/node_modules/enhanced-resolve/lib/CachedInputFile  System.js:38:16)
      at ReadFileContext.callback (/Users/crucialfelix/code/matterminds/node_modules/graceful-fs/graceful-fs.js:7  8:16)
      at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:334:13)
   @ ./made/default/src/layouts/index.js 6:0-23

develop failure (with tilde):

made/default/src/layouts/layout.css
1:1	⚠  Failed to find '~purecss/build/pure.css'
    in [
        /Users/crucialfelix/code/matterminds/made/default/src/layouts
    ] [postcss-import]
2:1	⚠  Failed to find '~purecss/build/grids-responsive.css'
    in [
        /Users/crucialfelix/code/matterminds/made/default/src/layouts
    ] [postcss-import]

 WARNING  Compiled with 2 warnings                                                                       15:43:42

 warning  in ./made/default/src/layouts/layout.css

postcss-import: /Users/crucialfelix/code/matterminds/made/default/src/layouts/layout.css:1:1: Failed to find '~purecss/build/pure.css'
    in [
        /Users/crucialfelix/code/matterminds/made/default/src/layouts
    ]

Environment

matterminds ❯ gatsby info --clipboard

  System:
    OS: macOS High Sierra 10.13.3
    CPU: x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.1.0 - ~/.nvm/versions/node/v10.1.0/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.1.0 - ~/.nvm/versions/node/v10.1.0/bin/npm
  Browsers:
    Chrome: 66.0.3359.181
    Safari: 11.0.3
  npmPackages:
    gatsby: 1.9.269 => 1.9.269
    gatsby-link: 1.6.44 => 1.6.44
    gatsby-plugin-antd: 1.0.12 => 1.0.12
    gatsby-plugin-react-helmet: 2.0.11 => 2.0.11
    gatsby-plugin-sass: 1.0.26 => 1.0.26
    gatsby-source-filesystem: 1.5.38 => 1.5.38
    gatsby-transformer-json: 1.0.19 => 1.0.19
  npmGlobalPackages:
    gatsby-cli: 1.1.58
    gatsby: 1.9.270

File contents (if changed)

gatsby-config.js: N/A

module.exports = {
  siteMetadata: {
    title: "Default Website"
  },
  plugins: [
    "gatsby-plugin-react-helmet",
    "gatsby-transformer-json",
    "gatsby-plugin-sass",
    {
      resolve: "gatsby-source-filesystem",
      options: {
        path: "./src/data/"
      }
    },
    "gatsby-plugin-antd"
  ]
};

package.json: N/A

{
  "name": "matterminds",
  "version": "1.0.0",
  "description": "MVP Generator for production of websites from data input",
  "main": "index.js",
  "scripts": {
    "make": "ts-node make.ts",
    "activate": "ts-node activate.ts",
    "start": "gatsby develop",
    "build": "gatsby build",
    "serve": "gatsby serve",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Chris Sattinger",
  "license": "All rights reserved",
  "dependencies": {
    "@types/es6-promise": "3.3.0",
    "@types/js-yaml": "3.11.1",
    "@types/lodash": "4.14.109",
    "@types/make-dir": "1.0.3",
    "@types/mz": "0.0.32",
    "@types/node": "10.3.0",
    "@types/recursive-readdir": "2.2.0",
    "gatsby": "1.9.269",
    "gatsby-link": "1.6.44",
    "gatsby-plugin-antd": "1.0.12",
    "gatsby-plugin-react-helmet": "2.0.11",
    "gatsby-plugin-sass": "1.0.26",
    "gatsby-source-filesystem": "1.5.38",
    "gatsby-transformer-json": "1.0.19",
    "js-yaml": "3.11.0",
    "lodash": "4.17.10",
    "make-dir": "1.3.0",
    "mz": "2.7.0",
    "purecss": "1.0.0",
    "react-helmet": "5.2.0",
    "recursive-readdir": "2.2.2",
    "ts-node": "6.0.5",
    "typescript": "2.9.1"
  }
}

gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

@KyleAMathews
Copy link
Contributor

Do you have any expertise in how webpack should be setup to fix this? We're lacking in Sass experts here it seems so a PR from you fixing up gatsby-plugin-sass would be amazing!

@crucialfelix
Copy link
Author

I have a fair amount of experience wrestling with webpack. Not sure if I have time, but I will try to have a look deeper.

I'm not sure that it is sass related. This was a pure css file. Maybe it works if I convert it to sass.

Notes for me or someone else:

sass webpack loader should be:

{
            loader: 'sass-loader',
            options: {
              "includePaths": [
                require('path').resolve(__dirname, 'node_modules')
              ]
            }
          }

The css-loader docs are here: https://webpack.js.org/loaders/css-loader/

@m-allanson m-allanson added type: bug An issue or pull request relating to a bug in Gatsby help wanted Issue with a clear description that the community can help with. labels Jun 8, 2018
@nihgwu
Copy link
Contributor

nihgwu commented Jun 9, 2018

I have a similar styles import and don't have this issue with Gatsby v2

@Chris927
Copy link

@crucialfelix FWIW, the non-tilde case seems to be fine if I configure (in gatsby-config.js) the sass plugin as follows:

    {
      resolve: `gatsby-plugin-sass`,
      options: {
        includePaths: [
          require('path').resolve(__dirname, 'node_modules')
        ]
      }
    },

This is pretty much your suggested webpack loader config applied.

@crucialfelix
Copy link
Author

Great, thanks for the responses ! I will try it and then see about a PR for 1.9. Looking forward to moving to 2 myself.

@crucialfelix
Copy link
Author

I renamed layout.css to layout.scss which means gatsby-plugin-sass is handling it.

This means that this gatsby-config.js works:

    {
      resolve: `gatsby-plugin-sass`,
      options: {
        includePaths: [
          require('path').resolve(__dirname, 'node_modules')
        ]
      }
    },

To get it work for css imports I think we can modify the base webpack config something like this:

In gatsby-node.js:

module.exports = {
  modifyWebpackConfig: function modifyWebpackConfig(config, env) {
    config.merge({
      resolve: {
        include: [require("path").resolve(__dirname, "./node_modules")]
      }
    });
    return config;
  }
};

but apparently that is an out of date example and config.merge is not a function.

v1 docs: https://github.com/gatsbyjs/gatsby/blob/v1/docs/docs/add-custom-webpack-config.md
v2 docs: https://github.com/gatsbyjs/gatsby/blob/v2/docs/docs/add-custom-webpack-config.md

So path of least resistance for me is to just use .scss files. This happens a lot with webpack. Exhaustion sets in, budget runs out, you take the first exit.

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Dec 8, 2018
@gatsbot
Copy link

gatsbot bot commented Dec 8, 2018

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!

@gatsbot
Copy link

gatsbot bot commented Dec 19, 2018

This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with. stale? Issue that may be closed soon due to the original author not responding any more. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

5 participants