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

How to configure import alias #327

Open
Necrometal opened this issue Jun 15, 2023 · 2 comments
Open

How to configure import alias #327

Necrometal opened this issue Jun 15, 2023 · 2 comments

Comments

@Necrometal
Copy link

I wanted to add alias import in an Enact project: i configured the tsconfig.json like bellow:
{ "compilerOptions": { "target": "es5", "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", "paths": { "@App/*": ["./src/App/*"], "@Components/*": ["./src/Components/*"], "@Views/*": ["./src/Views/*"] }, }, "include": [ "src", "types" ] }

and i saw in readme that there is alias that can be added to the enact object in package.json:

"alias": { "@App/*": ["./src/App/*"], "@Components/*": ["./src/Components/*"], "@Views/*": ["./src/Views/*"] }

i don't if it's the right way to it or alias import is not available in Enact but when i make import like:
import MyComponent from '@Components/MyComponent
It said can't resolve @Components/MyComponent.

@hong6316
Copy link
Contributor

Could you try using enact object in package.json?
For example:

{
	...
	"enact": {
		"theme": "sandstone",
		"alias": {
			"@App/*": ["./src/App/*"], 
			"@Components/*": ["./src/Components/*"], 
			"@Views/*": ["./src/Views/*"] },
		}
	}
	...
}

Reference: https://github.com/enactjs/cli/blob/master/README.md#enact-build-options

@Michel-HaiRUn
Copy link

{ "compilerOptions": { "target": "es5", "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", "paths": { "@App/": ["./src/App/"], "@Components/": ["./src/Components/"], "@Views/": ["./src/Views/"] }, }, "include": [ "src", "types" ] }

as i already mentionned in my topic, already tried it but i still got the error can't resolve

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

No branches or pull requests

3 participants