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 is not working (SyntaxError: Unexpected token) #970

Closed
gseidel opened this issue Aug 2, 2020 · 3 comments
Closed

Dynamic import is not working (SyntaxError: Unexpected token) #970

gseidel opened this issue Aug 2, 2020 · 3 comments

Comments

@gseidel
Copy link

gseidel commented Aug 2, 2020

Seems like acorn is not supporting dynamic import statements. I saw issue #809, but i'm not sure if this is related, because some comments say something about a dependency to npm, but i can reproduce it without npm.

How to reproduce

let acorn = require("acorn");

let code = `async function load() {
    let say = await import('./say.js');
}`;

console.log(acorn.parse(code));

Output

SyntaxError: Unexpected token (2:20)
    at Parser.pp$4.raise (./node_modules/acorn/dist/acorn.js:2927:15)
    at Parser.pp.unexpected (./node_modules/acorn/dist/acorn.js:698:10)
    at Parser.pp$3.parseExprAtom (./node_modules/acorn/dist/acorn.js:2322:21)
    at Parser.pp$3.parseExprSubscripts (./node_modules/acorn/dist/acorn.js:2129:21)
    at Parser.pp$3.parseMaybeUnary (./node_modules/acorn/dist/acorn.js:2106:19)
    at Parser.pp$3.parseAwait (./node_modules/acorn/dist/acorn.js:2912:26)
    at Parser.pp$3.parseMaybeUnary (./node_modules/acorn/dist/acorn.js:2090:19)
    at Parser.pp$3.parseExprOps (./node_modules/acorn/dist/acorn.js:2041:21)
    at Parser.pp$3.parseMaybeConditional (./node_modules/acorn/dist/acorn.js:2024:21)
    at Parser.pp$3.parseMaybeAssign (./node_modules/acorn/dist/acorn.js:1997:21) {
  pos: 44,
  loc: Position { line: 2, column: 20 },
  raisedAt: 50
}

Version
node v12.18.2
acorn 7.3.1

@marijnh
Copy link
Member

marijnh commented Aug 3, 2020

You have to specify ecmaVersion: 11 to parse dynamic import.

@marijnh marijnh closed this as completed Aug 3, 2020
kodiakhq bot pushed a commit to vercel/next.js that referenced this issue Nov 5, 2021
- Code splitting should be disabled for the server-web build. Done via `ServerlessPlugin`.
- ~Target can't be `web`, `webworker` is better.~ Using `web` and `es6` for now, still not ideal.
- acornjs/acorn#970

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
…30972)

- Code splitting should be disabled for the server-web build. Done via `ServerlessPlugin`.
- ~Target can't be `web`, `webworker` is better.~ Using `web` and `es6` for now, still not ideal.
- acornjs/acorn#970

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
@blaasvaer
Copy link

blaasvaer commented Feb 19, 2025

And WHERE do one specify ecmaVersion: 11? I'm using Browserify with Babel and have no clue where to configure specifically for Acorn. I would expect to do all my configuring at the Browserify/Babel level and not at the level of some obscure and deeply nested dependency?

@RReverser
Copy link
Member

Babel does not use Acorn, consult the docs of libraries you actually use.

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

4 participants