no, I use yarn and it's the latest
I want to add some common alias in both prod and dev webpack configuration files. To avoid repetitive coding I decided to write them in paths.js, like this:
...
// config after eject: we're in ./config/
module.exports = {
...
servedPath: getServedPath(resolveApp('package.json')),
//common alias
resolvePaths: {
pages: resolveApp('src/pages'),
common: resolveApp('src/common'),
utils: resolveApp('src/utils'),
components: resolveApp('src/components'),
modals: resolveApp('src/components/Modals')
}
};
Then I use it in both configuration files, like this:
resolve: {
...
extensions: ['.js', '.json', '.jsx', ''],
alias: Object.assign(paths.resolvePaths,{
'react-native': 'react-native-web',
})
}
But it doesn't work and some weird errors show up:
Failed to compile.
Error in ./src/common/less/base.less
Syntax error: Unexpected '}' at line 1 column 16 of the JSON5 data. Still to read: "}"
@ ./src/common/less/base.less 4:14-192 13:2-17:4 14:20-198
...
// config after eject: we're in ./config/
module.exports = {
...
servedPath: getServedPath(resolveApp('package.json')),
//common alias
pages: resolveApp('src/pages'),
common: resolveApp('src/common'),
utils: resolveApp('src/utils'),
components: resolveApp('src/components'),
modals: resolveApp('src/components/Modals')
};
And use it in configuration files like this:
resolve: {
...
extensions: ['.js', '.json', '.jsx', ''],
alias: {
'react-native': 'react-native-web',
'common': paths.common,
'pages': paths.pages,
...
})
}
It will work.
It works correctly.
Run these commands in the project folder and fill in their results:
npm ls react-scripts (if you haven鈥檛 ejected): have ejectednode -v: v6.10.2npm -v: 4.6.1Then, specify:
Thanks.
Since you have ejected, we encourage you to ask for help in channels specific to underlying projects (in this case, webpack). We only know our own configuration well, and we can鈥檛 really provide support for every possible change in the configuration. I鈥檒l close this as it鈥檚 not very actionable for us, but maybe somebody who knows webpack well can help you. Cheers!
Please open this issue on Stack Overflow or similar help community.
Unfortunately, we are too busy to provide support for ejected setups. Sorry!
This seems like a malformed webpack loader configuration or invalid syntax in your LESS.
Please be mindful to read all the comments we have around the loader section.
If something's not clear, please let us know or send a PR improving the documentation. Thanks!
@gaearon @Timer ok, I'll ask some other places. thanks for your reply.
FWIW, if you鈥檙e just trying to enable absolute imports like import MyPage from 'pages/MyPage' you didn鈥檛 need to eject. You can just create an .env file in your project and add NODE_PATH=src to it.
I'll try it. Again, thank you for your help.
Most helpful comment
FWIW, if you鈥檙e just trying to enable absolute imports like
import MyPage from 'pages/MyPage'you didn鈥檛 need to eject. You can just create an.envfile in your project and addNODE_PATH=srcto it.