-
Notifications
You must be signed in to change notification settings - Fork 12.8k
module
... was resolved to '...', but '--allowJs' is not set
error for explicit node_module import
#15970
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
Comments
there are a few issues going on here. first
I believe this is the real bug here that needs to be fixed. if the file is found on disk, you should not get this error message. |
module
... was resolved to '...', but '--allowJs' is not set
error for explicit node_module import
With allowJs on, we are running into a similar issue like the one described in #15755 |
I had the same problem. I did |
Huge bummer in my early learning stage, I've been like a week trying to find a workaround!. Same experience, turning allowJs ON mess up the entire Angular app. I'd have expected to turn it on for arbitrary directories/files. |
If you're using typescript, just rename the file extension to .ts instead of .js. (foo.ts) . |
@coffeenexus vs code says foo.ts is not a node module |
@aritrabasu104 To be a module it must have an |
@Andy-MS hi, is there any way to use exports.x rather than switch to ES6 syntax? Such as transpiling? |
@AbnerZheng There's no way to transpile "up" from commonjs to es6. It you're writing JS code you can use commonjs syntax, but it isn't allowed in TypeScript. |
@Andy-MS, as I know, refactor means a action .So after refacting, my file's content will be changed,from "module.export " to exports, rather than changing the behavior of tsc. Is this right? I'm now working with vscode/webstorm intelligense autocompletion of eggjs framework. Since eggjs have d.ts files, the function autocompletion works well. But there are some problems. We use declartion merge of ts to mixin user's custom Controller/or Service singleton to eggjs's type definition. For example, now I use declartion merge, creating a file: '''home.js''' This doesn't work, But When I change to the way of exports default HomeController. All works great. |
Another problem: In May be a good idea to just write a |
@Andy-MS Yes, you're right. These two problem exist, and after I fixed them, it still won't work. But as I change the way export to es6, everything works fine. |
TypeScript Version: 2.3.2
Code
Project layout:
tsonfig.json:
index.ts:
Expected behavior:
Compilation works
Actual behavior:
error TS6059: File '/Users/justin/Documents/Projects/test/node_modules/foo/foo.js' is not under 'rootDir' '/Users/justin/Documents/Projects/test/src'. 'rootDir' is expected to contain all source files.
error
My
lib/
directory, which should contain just the compiled contents ofsrc/
containssrc/
andnode_modules/
subdirectories.If I remove
allowJs
, then tsc complains that I'm importing JS and need to add the option.The text was updated successfully, but these errors were encountered: