Skip to content
This repository has been 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

Open
neurocmd opened this issue Aug 19, 2021 · 0 comments

Comments

@neurocmd
Copy link

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?

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

No branches or pull requests

1 participant