question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not following webpack aliases

See original GitHub issue

When using webpack aliases, docz won’t follow them, giving the following error:

ERROR  Failed to compile with 3 errors     
These dependencies were not found:

* _atoms/overlay in [...]molecules/fields/clockField.js
* _molecules/fields/textField in [...]/molecules/fields/clockField.js
* _molecules/popup in [...]/molecules/fields/clockField.js

To install them, you can run: npm install --save _atoms/overlay _molecules/fields/textField _molecules/popup

My webpack config:

[...]
resolve: {
        modules: ['node_modules', 'src/common',],
        alias: {
            _usvc: path.resolve(__dirname, 'src/usvc'),
            _templates: path.resolve(__dirname, 'src/common/templates'),
            _organisms: path.resolve(__dirname, 'src/common/organisms'),
            _molecules: path.resolve(__dirname, 'src/common/molecules'),
            _atoms: path.resolve(__dirname, 'src/common/atoms'),
            _app: path.resolve(__dirname, 'src/appComponents'),
            _: path.resolve(__dirname, 'src'),
        },
    },
[...]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
rakannimercommented, Nov 1, 2019

Hey @GradyTruitt

To be able to use absolute imports from ./src you’ll need to modify the docz webpack config to tell it how to resolve paths like "icons/Icons".

To do that, add a gatsby-node.js file in your root directory :

const path = require('path')

exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({
    resolve: {
	// Note the '..' in the path because the docz gatsby project lives in the `.docz` directory
      modules: [path.resolve(__dirname, '../src'), 'node_modules'],
    },
  })
}

You can also see a complete working example here : https://github.com/doczjs/docz/tree/master/examples/webpack-alias

2reactions
nicholasesscommented, Aug 22, 2018

@gmarconi I have a suggestion:

First you can create a file with function called setAlias example:

const path = require("path");
module.exports = config => {
  let newalias = {
    "@src": path.join(__dirname, "..", "src"),
    "@components": path.join(__dirname, "..", "src/components"),
    "@assets": path.join(__dirname, "..", "src/assets"),
    "@pages": path.join(__dirname, "..", "src/pages"),
    "@helpers": path.join(__dirname, "..", "src/helpers")
  };

  config.resolve.alias = { ...config.resolve.alias, ...newalias };
  return config;
};

In webpack, you will set alias with function

import setAlias from "./config/setAlias";
let webpackObj = {/* plugins, entry, outputs, alias,  etc */}
module.exports = setAlias(webpackObj);

In doczrc, the same thing that above

import setAlias from "./config/setAlias";

export default {
  modifyBundlerConfig: config => setAlias(config)
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack doesn't resolve properly my alias
I am trying to have a namespace for my app to work as a module, and import my components using this namespace and...
Read more >
Not following webpack aliases · Issue #243 · doczjs/docz
When using webpack aliases, docz won't follow them, giving the following error: ERROR Failed to compile with 3 errors These dependencies ...
Read more >
Webpack Aliases Keep My Code Sane
Aliases are a way to let webpack know where to find our code by providing a word or character that represents a partial...
Read more >
Resolve
resolve.alias. object. Create aliases to import or require certain modules more easily. For example, to alias a bunch of commonly used src/ folders:....
Read more >
Webpack aliases not resolved when using ... - YouTrack
I have the following config inside a Webpack config file called "webpack.config.dev.js" which lives inside a "config" folder: alias: { 'app': ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found