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'
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'],
},
// ...
};
// ...
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
Please help me resolve this issue :)
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.
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.
@frenzzy Private links should not be here :-)
@Kohze Are you still interested or this can be closed? If so, reopen please :-)
oops, was a wrong link)
@frenzzy can you write sample internals config for src folder?
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));
},
],
// ...
};
// ...
... and solution for Atom js-hyperclick
Most helpful comment
sure, for example if you want to make
import Header from 'src/components/Header'works: