ijt
ijt

Reputation: 3845

In Elixir/Phoenix, getting Uncaught SyntaxError: The requested module '/js/hi.js' does not provide an export named 'hiya'

In my Elixir/Phoenix app, I added a file called assets/js/hi.js with these contents:

export function hiya() {
    console.log('hiya from hi.js');
}

I updated webpack.config.js to include this:

    entry: {
      'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js']),
...
      'hi': ['./js/hi.js']
    },

In my template, I have this code:

  <script type="module">
    import { hiya } from "/js/hi.js";
...
  </script>

When I load the page the following error appears in the console:

Uncaught SyntaxError: The requested module '/js/hi.js' does not provide an export named 'hiya'

How can I get the import to work?

Upvotes: 1

Views: 140

Answers (1)

ijt
ijt

Reputation: 3845

I got it working by removing the 'hi' entry from webpack.config.js, putting hi.js into assets/static/js and restarting the Phoenix server. This made the /js/hi.js path return the literal contents of hi.js without any modifications from webpack. Apparently those modifications were causing the problem.

Upvotes: 2

Related Questions