`Unexpected character '@'` when using path aliases
See original GitHub issueWhat 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/*"]
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
Initially tsconfig was without “compileOnSave” option, but with adding this option to tsconfig file I have two funny errors:
Thats why I need to workaround through adding “tsconfigOverride” =(
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 withintsconfigOverrides
.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
, andts-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 usedrollup-plugin-import-resolver
, which is a plugin for resolving things like path aliases.