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

Cant resolve modules #1155

Closed
kuongknight opened this issue Mar 2, 2017 · 11 comments
Closed

Cant resolve modules #1155

kuongknight opened this issue Mar 2, 2017 · 11 comments

Comments

@kuongknight
Copy link

In webpack config we have: resolve: { modules: [path.resolve(__dirname, '../src'), 'node_modules'], }
But when import Link from 'components/Link'
Found error:
Error: Cannot find module 'components/Link'

@frenzzy
Copy link
Member

frenzzy commented Mar 2, 2017

You need to explicitly specify this option for client and server config separately, because webpack mutates this section =/

// tools/webpack.config.js

// ...

const clientConfig = {
  // ...
  resolve: {
    modules: [path.resolve(__dirname, '../src'), 'node_modules'],
  },
  // ...
};

const serverConfig = {
  // ...
  resolve: {
    modules: [path.resolve(__dirname, '../src'), 'node_modules'],
  },
  // ...
};

// ...

@kuongknight
Copy link
Author

kuongknight commented Mar 9, 2017

currently we have:

const config = {
resolve: {
    modules: [path.resolve(__dirname, '../src'), 'node_modules']
  }
}
const clientConfig = {
  // ...
  resolve: { ...config.resolve },
  // ...
};

const serverConfig = {
  // ...
  resolve: { ...config.resolve },
  // ...
};

But it not working

@kuongknight
Copy link
Author

Please help me resolve this issue :)

@frenzzy
Copy link
Member

frenzzy commented Mar 11, 2017

If you want to use absolute paths to your modules you also need to mark your modules as internal here for server-side bundle or copy them manually to the build folder so that build/server.js can find them.

@Kohze
Copy link

Kohze commented Mar 12, 2017

If you want to use absolute paths to your modules you also need to mark your modules as internal here for server-side bundle or copy them manually to the build folder so that build/server.js can find them.

the link is not working or private - have a similar issue with installing react-office-fabric and then not resolving because of the /src/ in between the path resolve.

@langpavel
Copy link
Collaborator

langpavel commented Mar 12, 2017

@frenzzy Private links should not be here :-)

@langpavel
Copy link
Collaborator

langpavel commented Mar 12, 2017

@Kohze Are you still interested or this can be closed? If so, reopen please :-)

@frenzzy
Copy link
Member

frenzzy commented Mar 13, 2017

oops, was a wrong link)

@kuongknight
Copy link
Author

@frenzzy can you write sample internals config for src folder?

@frenzzy
Copy link
Member

frenzzy commented Mar 15, 2017

sure, for example if you want to make import Header from 'src/components/Header' works:

// tools/webpack.config.js

// ...

const clientConfig = {
  // ...
  resolve: {
    modules: [path.resolve(__dirname, '..'), 'node_modules'],
  },
  // ...
};

const serverConfig = {
  // ...
  resolve: {
    modules: [path.resolve(__dirname, '..'), 'node_modules'],
  },
  externals: [
    /^\.\/assets\.json$/,
    (context, request, callback) => {
      const isExternal =
        request.match(/^[@a-z][a-z/.\-0-9]*$/i) &&
        !request.match(/^src\//i) && // module is not external if starts with `src/`
        !request.match(/\.(css|less|scss|sss)$/i);
      callback(null, Boolean(isExternal));
    },
  ],
  // ...
};

// ...

@comerc
Copy link

comerc commented Mar 17, 2017

... and solution for Atom js-hyperclick

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

No branches or pull requests

5 participants