-
-
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
TypeScript modules not resolved when using "baseUrl". #4136
Comments
Thanks @igor-dv its all working a treat now. And the build time has gone from 7 minutes down to 20 seconds 🚗 💨 Here's my
|
@cwmrowe
how does it work though? This seems specific to how webpack resolves module, and may or may not be directly co-related to how tsconfig is setup (?) |
If it's useful to anyone, I'm doing this to avoid duplicating // webpack.config.js
const path = require('path');
const { compilerOptions } = require('./tsconfig.json');
module.exports = {
// other stuff
resolve: {
modules: [
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, compilerOptions.baseUrl),
],
},
}; |
I highly recommend using tsconfig-paths-webpack-plugin for aliases. CC: @shilman - i feel like this is worth recommending at least in FAQ or maybe out of the box setup: const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
stories: ['../**/*.stories.mdx', '../**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
webpackFinal: async (config) => {
config.resolve.plugins.push(new TsconfigPathsPlugin({}));
return config;
},
}; |
@kylemh I'm using it but it still not working on my project. I have a NextJS project and everything works as expected locally, but the Storybook's build breaks because of it warns about every import on the project (including everything inside I'm using the latest versions of everything in the project |
Share your config |
@kylemh I don't have a const path = require('path')
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')
module.exports = {
stories: ['../src/components/**/stories.tsx'],
addons: ['@storybook/addon-essentials', 'storybook-addon-next-router'],
babel: async (options) => ({
...options,
plugins: [
...options.plugins,
require.resolve('@babel/plugin-transform-react-jsx')
]
}),
webpackFinal: async (config) => {
config.resolve.modules = [
...(config.resolve.modules || []),
path.resolve(__dirname, '../src')
]
config.resolve.plugins = [
...(config.resolve.plugins || []),
new TsconfigPathsPlugin()
]
return config
}
} EDIT: my project's structure is something like this
|
I worry that your module resolve is getting in the way of the TS Config Paths plugin. Can you copy my |
@kylemh still doesn't work but the error was different though. here my {
"compilerOptions": {
"baseUrl": "src",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
} |
Is it because you should have
|
@kylemh but my files actually are named as
as I told earlier: Storybook works just fine in localhost. the problem is just when I build it to generate the static files to host it online. |
Damn. Well I'm not certain, but you shouldn't be using a customer module resolver along with the TS plugin 🤷♂️ |
Support request summary
@storybook/angular
is not resolving non-relative imports. I believe non-relative imports are a relative new feature of TypeScript that allow you to reference imports from abaseUrl
rather than always using relative imports to your own code.I think that support for this feature should be a priority as VS Code will now rename all your modules to use non-relative imports automatically when you move/rename a file so its difficult problem to avoid.
Steps to reproduce
Create a strorybook project with Angular 6.1.1 and use non-relative imports in your code, e.g.
src/app/somefile.ts
Please specify which version of Storybook and optionally any affected addons that you're running
Affected platforms
Windows 10
Workaround
I have managed to work around this using the
TsconfigPathsPlugin
and modifying mytsconfig.json
file to usecompilerOptions.paths
(note the mappings look slightly ridiculous)..storybook/tsconfig.json
NB:
compilerOptions.baseUrl
has a value of "./src" in my roottsconfig.json
.storybook/webpack.config.js
NB: The initial build is also excruciatingly slow, but I don't think its related.
The text was updated successfully, but these errors were encountered: