-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Angular] Storybook doesn't work with non-relative imports #2718
Comments
Same thing is happening with create-react-app. Edit: Resolved the CRA issue by adding NODE_PATH=src in my package.json
Although it would be nice if it read from my |
By "non-relative imports", you mean paths mapping in tsconfig.json? |
I have the same problem: "Module not found: Error: Can't resolve '@gorila/core/utils'" in tsconfig.json: |
A possible workaround could be this - #2616 (comment) I think we will need to add something like this by default to storybook. |
I have set following code in webpack.config.js
this setting has solved the issue. #3258 |
The workaround by @morninng almost worked with few adjustments:
This file does not exist. |
@DmitryEfimenko , can you please share your result for sake of clarity |
sure, below is the final const path = require('path');
var fs = require("fs");
const findUp = require('find-up');
module.exports = (baseConfig) => {
const tsFile = findUp.sync('tsconfig.json');
const tsConfig = JSON.parse(fs.readFileSync(tsFile));
const root = path.join(path.dirname(tsFile), tsConfig.compilerOptions.baseUrl);
if (!baseConfig.resolve.alias) {
baseConfig.resolve.alias = {};
}
for (const prop in tsConfig.compilerOptions.paths) {
// expects something like: "@pwa/*": ["projects/pwa/src/app/*"]
const val = tsConfig.compilerOptions.paths[prop][0];
const alias = prop.substring(0, prop.length - 2);
const resolvePath = val.substring(0, val.length - 2);
baseConfig.resolve.alias[alias] = path.join(root, resolvePath);
}
baseConfig.entry.styles[0] = baseConfig.entry.styles[0].replace('\\projects\\pwa\\projects\\pwa', '\\projects\\pwa');
return baseConfig;
}; Notice the shenanigans with |
By the way, I think I understand why the issue with styles came around. It's probably worth opening a new issue specifically for that. Anyhow, the command I run to start storybook is:
As you can see, my project is in |
Thanks @DmitryEfimenko Here is a storybook 5.1 version equivalent (except for the 'style' part) : const path = require('path');
var fs = require("fs");
const findUp = require('find-up');
module.exports = ({ config, mode }) => {
const tsFile = findUp.sync('tsconfig.json');
const tsConfig = JSON.parse(fs.readFileSync(tsFile));
const root = path.join(path.dirname(tsFile), tsConfig.compilerOptions.baseUrl);
if (!config.resolve.alias) {
config.resolve.alias = {};
}
for (const prop in tsConfig.compilerOptions.paths) {
// expects something like: "@pwa/*": ["projects/pwa/src/app/*"]
const val = tsConfig.compilerOptions.paths[prop][0];
const alias = prop.substring(0, prop.length - 2);
const resolvePath = val.substring(0, val.length - 2);
config.resolve.alias[alias] = path.join(root, resolvePath);
}
return config;
} |
MMM, why do I still have to do this ? |
@sparqueur resolved it with https://yarnpkg.com/en/package/tsconfig-paths-webpack-plugin |
Non-relative imports like this
doesn't work in stories file
I can fix it by using relative path
but if
test.component
has non-relative import it would have the same errorstorybook/angular 3.4.0-alpha.1
The text was updated successfully, but these errors were encountered: