You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This could be by design but it just surprised me and I wanted to verify behavior.
With CommonJS, relative modules must start with "./" or "../", otherwise it's considered to be a top-level module.
As near as I can tell with ES6, module naming is "loader implementation specific". It would seem that TypeScript's implementation does not require "./" or "../" to reference a relative file. For example:
Is this intended? I'm not super familiar with prevailing ES6 module loading standards, but I put together a quick test using SystemJS. It also does not allow referencing a relative module without './' or '../' unless that module happens to be in the preconfigured "base" URL. In other words, the above example would probably work out of the box, but the following would not:
// components/helper.tsexportfunctionsomeHelper();// components/dep.tsimport*ashelperfrom'helper';// this line would error at runtime in SystemJS, but not in TSexportclassTest{}// app.tsimport{Test}from'components/dep';
My understanding is that work is being made in #2338 and things like #4154 which may help to alleviate issues like this since it would allow TypeScript to be aware of that "loader-implementation specific" part. In the meantime, is the current default correct? As an alternative, perhaps it would make sense for ES6 imports to not have this behavior if --module commonjs is set, since this clearly does not follow the CJS spec.
The text was updated successfully, but these errors were encountered:
@jbrantly the current module resolution logic is a bit weird :D. if you are loafing module "helpers", the compiler will look for a file called "helpers.d.ts" in the current directory, then will keep walking up the directory tree searching for "helpers.d.ts"...
obviously this is not correct, hence #2338. @vladima is actively working on this now. so hopefully we have some relief soon.
but just to make sure i understood correctly, you want it to be an error to not use "./" or "../" with relative modules?
This could be by design but it just surprised me and I wanted to verify behavior.
With CommonJS, relative modules must start with "./" or "../", otherwise it's considered to be a top-level module.
As near as I can tell with ES6, module naming is "loader implementation specific". It would seem that TypeScript's implementation does not require "./" or "../" to reference a relative file. For example:
Is this intended? I'm not super familiar with prevailing ES6 module loading standards, but I put together a quick test using SystemJS. It also does not allow referencing a relative module without './' or '../' unless that module happens to be in the preconfigured "base" URL. In other words, the above example would probably work out of the box, but the following would not:
My understanding is that work is being made in #2338 and things like #4154 which may help to alleviate issues like this since it would allow TypeScript to be aware of that "loader-implementation specific" part. In the meantime, is the current default correct? As an alternative, perhaps it would make sense for ES6 imports to not have this behavior if --module commonjs is set, since this clearly does not follow the CJS spec.
The text was updated successfully, but these errors were encountered: