Skip to content
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

Dynamic import() error #399

Closed
ltheinrich opened this issue Apr 15, 2021 · 8 comments
Closed

Dynamic import() error #399

ltheinrich opened this issue Apr 15, 2021 · 8 comments

Comments

@ltheinrich
Copy link

main.js

import("./test.js").then((module) => { console.log(module.message)});

test.js

export const message = "This should print!";

It should work, but instead I get an error (since v2.9.16):

ERROR: cannot minify main.js: expected String, Identifier, *, or { instead of ( in import statement on line 1 and column 7
    1: import("./test.js").then((module) => { console.log(module...
             ^
@tdewolff
Copy link
Owner

Thanks for the report. However, looking at the specification at https://tc39.es/ecma262/#sec-imports I don't see any definition of this syntax. Is this from a syntax proposal?

@ltheinrich
Copy link
Author

I did not notice, it is actually from a proposal. But the feature is supported by most modern browsers.
This should be the proposal: https://github.com/tc39/proposal-dynamic-import
My project uses dynamic imports, so I would appreciate if you could implement it.

@ltheinrich
Copy link
Author

Now I have found it in the specification (Import Calls): https://tc39.es/ecma262/#sec-import-calls
So it looks like it was already approved.

@tdewolff
Copy link
Owner

Yes, this looks actually like a bug. I'm on it!

@tdewolff
Copy link
Owner

Let me know if it is working for you now!

@ltheinrich
Copy link
Author

Hi, I compiled the master branch using Go 1.15.8 and it shows a different error (used the main.js code from above):

[lennart@nexus minify]$ go version
go version go1.15.8 linux/amd64
[lennart@nexus minify]$ go build -o minify-8d45d96
[lennart@nexus minify]$ minify-8d45d96 main.js
/usr/local/bin/minify-8d45d96: line 1: syntax error near unexpected token `newline'
/usr/local/bin/minify-8d45d96: line 1: `!<arch>'
[lennart@nexus minify]$

@tdewolff
Copy link
Owner

I'm not sure what that is, it seems to work fine here and Travis builds fine. Perhaps a problem at your end?

@ltheinrich
Copy link
Author

Yes, it was a problem on my end.
I built it using make install now and it works. Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants