Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

"Cannot use import statement outside a module" error when import statement is used inside template #56

@neurocmd

Description

@neurocmd

I can't use import statement inside ejs template. esModule option of ejs-loader loader is set to true. And I am facing the "Cannot use import statement outside a module" error.

<%
  import example from '../components/example/example.ejs'
%>

<div class="container">
  <%= example({ title: 'Some title' }) %>
</div>

My guess is that this is due to the import being inside a function, which is not the correct syntax:

export default function(props) {
  //...
  import example from '../components/example/example.ejs'
  //...
}

Is it possible to move the import statements to the top level of the generated es module?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions