Skip to content

Unexpected character '@' when using path aliases #164

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

Closed
viT-1 opened this issue Aug 2, 2019 · 9 comments
Closed

Unexpected character '@' when using path aliases #164

viT-1 opened this issue Aug 2, 2019 · 9 comments
Labels
kind: support Asking for support with something or a specific use case problem: needs more info This issue needs more information in order to handle it problem: no repro No reproduction was provided (and have not tried to repro without one) problem: stale Issue has not been responded to in some time solution: invalid This doesn't seem right

Comments

@viT-1
Copy link

viT-1 commented Aug 2, 2019

What happens and why it is wrong

Just try same way
index.ts:
import SomeComponent from '@common/SomeComponent';
and got error:

Error: Unexpected character '@' (Note that you need plugins to import files that are not JavaScript)
at error (C:\Projects\PACWorld\Branches\PacWorldWeb3-vuejs\PacWorld3\node_modules\rollup\dist\rollup.js:9408:30)
at Module.error (C:\Projects\PACWorld\Branches\PacWorldWeb3-vuejs\PacWorld3\node_modules\rollup\dist\rollup.js:13347:9)
at tryParse (C:\Projects\PACWorld\Branches\PacWorldWeb3-vuejs\PacWorld3\node_modules\rollup\dist\rollup.js:13262:16)
at Module.setSource (C:\Projects\PACWorld\Branches\PacWorldWeb3-vuejs\PacWorld3\node_modules\rollup\dist\rollup.js:13573:33)
at Promise.resolve.catch.then.then.then (C:\Projects\PACWorld\Branches\PacWorldWeb3-vuejs\PacWorld3\node_modules\rollup\dist\rollup.js:16398:20)

Environment

Win10, MS Visual Studio 2019

Versions

  • typescript: 3.5.2
  • rollup: 1.17.0
  • rollup-plugin-typescript2: 0.22.1

rollup.config.js

const rolTts = require('ttypescript');
const rolTypescript = require('rollup-plugin-typescript2');
// ...
plugins: [
	rolTypescript({
		tsconfig: './src/tsconfig.json',
		clean: true,
		tsconfigOverride: {
			declaration: false,
			compileOnSave: false,
		},
		typescript: rolTts,
	}),
]

tsconfig.json

	"extends": "../tsproject.json",
	"compilerOptions": {
		"baseUrl": ".",
		"paths": {
			"@common/*": ["./common.blocks/*"]
		}
	}
@viT-1
Copy link
Author

viT-1 commented Aug 2, 2019

Initially tsconfig was without "compileOnSave" option,
but with adding this option to tsconfig file I have two funny errors:

rpt2: config error TS5023: Unknown compiler option 'compileOnSave'.
rpt2: config error TS5024: Compiler option 'compileOnSave' requires a value of type boolean.

Thats why I need to workaround through adding "tsconfigOverride" =(

@ezolenko
Copy link
Owner

ezolenko commented Aug 7, 2019

You need a rollup-plugin-node-resolve plugin in front of typescript plugin

@viT-1
Copy link
Author

viT-1 commented Aug 21, 2019

Now I haven't TS5023 & TS5024 errors but still have problems with '@'

@viT-1
Copy link
Author

viT-1 commented Aug 22, 2019

Please reopen the issue.
I try your rollup plugin with @zerollup/ts-transform-paths transformer configured two ways:

  1. through tsconfig.json >compilerOptions>plugins
  2. through typescript & transformers options

and still haven't success!
but have success (npm run deploy.dev & npm run www.dev) with npm run ttsc (ttypescript) which use only tsconfig.json with same @zerollup/ts-transform-paths

@ezolenko ezolenko reopened this Aug 23, 2019
@ezolenko
Copy link
Owner

ezolenko commented Aug 23, 2019

You can probably use transformers option on rpt2 plugin itself if you want to avoid ttypescript wrapper. Might have to shim the interfaces a bit to make @zerollup/ts-transform-paths work (or maybe not, let me know either way if you go this route).

@ezolenko
Copy link
Owner

ezolenko commented Aug 23, 2019

If ts-transform-paths works, is there anything to fix on this side though?

@viT-1
Copy link
Author

viT-1 commented Aug 23, 2019

I tried transformers (point 2), no success =(

@viT-1
Copy link
Author

viT-1 commented Aug 26, 2019

Migrate to rollup-plugin-typescript with rollup-plugin-import-resolver

@viT-1 viT-1 closed this as completed Aug 26, 2019
@agilgur5 agilgur5 added solution: invalid This doesn't seem right problem: stale Issue has not been responded to in some time labels May 11, 2022
@agilgur5 agilgur5 changed the title Error: Unexpected character '@' Unexpected character '@' when using path aliases May 11, 2022
@agilgur5 agilgur5 added problem: needs more info This issue needs more information in order to handle it problem: no repro No reproduction was provided (and have not tried to repro without one) labels May 11, 2022
@agilgur5
Copy link
Collaborator

I'm not sure what was going on in OP's codebase as no repro was provided and the issue they linked to (#159) was due to an invalid misconfiguration. The config posted here has a similar misconfiguration, compilerOptions is missing within tsconfigOverrides.

I also found the old commit from a repo they later linked (I modified their comment to point to the permalink as well), but didn't see a Rollup config there, so hard to tell what the issue was here.

It was likely a misconfiguration though, as lots of people have gotten path aliases, ttypescript, and ts-transform-paths working with this plugin; see #201 for one reference (can point to more in downstream TSDX as well).
OP also said in their last comment that they eventually used rollup-plugin-import-resolver, which is a plugin for resolving things like path aliases.

@agilgur5 agilgur5 added the kind: support Asking for support with something or a specific use case label May 11, 2022
Repository owner locked as resolved and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: support Asking for support with something or a specific use case problem: needs more info This issue needs more information in order to handle it problem: no repro No reproduction was provided (and have not tried to repro without one) problem: stale Issue has not been responded to in some time solution: invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants