-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Error when trying to use dynamic import with module: "es2015" #16675
Comments
"module": "es2015"
You'll want to use |
We should just be more helpful here. |
Thanks, it works! |
@DanielRosenwasser Does that mean if you want to target es5 you need to transpile the outputted JS with something like babel? Is there any other way to fool Typescript into emitting |
es2015 is ES6 and not es5. if you want to target es5, just set target to es5, and module to whatever module you are using. ES6 modules as they stand have no way to support |
Ah, right, the module compiler flag, not the target compiler flag. My bad. |
I always had Updated from 2.5.3 to 2.6.1 earlier today, ran NPM build in my React application and instead of getting errors like @Nitive did I got one bundle file instead of the usual multiple chunks. Changed Just leaving it here for people who might have a similar issue. |
Hey, Guys. Anything more I need to do? |
@hnviradiya9 please file a new issue with repro steps to reproduce the issue you are running into. |
Hi @mhegazy
and it throws an Error
|
you have |
I would like to take a look at improving the error message since this keeps coming up if this is OK. |
In angular project created by Angular CLI, I have two files Should I change |
@tomavic depends what you are after. If u wanna make it work for both app and unit tests then go for root. Cheers |
…e-for-dynamic-import Fix #16675: Better error message for dynamic import with ES2015 modules
thanks @paulkoerbitz! |
I have similar issue which I don't really understand. When I set in tsconfig:
It works. Though when I set
I have this error. |
"module": "esnext" is invalid in a jsconfig.json file.
|
@bennypowers Please check your typescript version, and write it here |
I try to "target": "es5", "target": "es6", and I have the same error. My typescript version is 2.8.3. Any suggestions? |
@facundocoto Which file are you trying to edit. tsconfig.json or tsconfig.app.json ? |
@tomavic I had to edit both, then works for me |
Having issues with
My jsconfig.json is:
When adding "module": "esnext" to jsconfig.json it still errors on import.meta.url, and a warning in jsconfig.json on the module line says:
Using Typescript 3.2.2 |
ES6" and "ES2015" values may be used when targeting "ES5" or lower. |
@hnviradiya9 After making the change |
Hi, |
TypeScript Version: 2.4.0
Code
tsconfig.json (short version)
Expected behavior:
No errors
Actual behavior:
Dynamic import cannot be used when targeting ECMAScript 2015 modules.
with non-obvious reasons why.Example repository
I get error
Dynamic import cannot be used when targeting ECMAScript 2015 modules.
when I try to use dynamic import inside typescript project with
"module": "es2015"
in configuration. The error message makes it clear that I can't use
import()
withes modules but it doesn't make sense because
import()
is part of es modules.However, it compiles correctly but throw annoing error.
I created a repository to reproduce an error.
npm run build-ts
: compile ts files intobuild/
folder.npm run build-webpack
: compile js intodist/
. (Then openindex.html
to see that everything works fine)The text was updated successfully, but these errors were encountered: