Importing custom js files into app.js - module error in dev mode

I’ve installed Sage 10 but I am unable to import a custom js function. I get the following console error:

app.js:913 Uncaught Error: Cannot find module './inc/test-js'

The file resides in /resources/scripts/inc/test-js.js and I’m importing it into /resources/scripts/app.js like so:

import {domReady} from '@roots/sage/client';
import test from './inc/test-js';
/**
 * app.main
 */
socket();
const main = async (err) => {
  if (err) {
    // handle hmr errors
    console.error(err);
  }
  // application code
 test();
}; 
...

The file in question looks like this:

function test() {
  alert('test');
}

export default test;

It only occurs in dev mode.

Where am I going wrong?

1 Like

Have you tried to add .js ?

import test from './inc/test-js.js';

I had a similar issue going from 10.3 to 10.4