Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found can't resolve

I've tried looking at some of the answers to this similar question but none of the solutions I have attempted from there have worked.

I'm trying to create a function in an external javascript file and I would like to use that function in my main javascript file.

File Structure

webpack.config.js
app
-- index.js
-- test.js

webpack.config.js

module.exports = {
    devtool: "cheap-module-source-map",
    entry: "./app/index.js",
    output: {
        filename: "public/bundle.js"
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query:
                {
                    presets: ['es2015']
                }
            }
        ]
    }
};

test.js

export default function test(message) {
    console.log(message);
}

index.js

"use strict"

import test from './app/test.js';

When attempting to run the webpack command I get the error:

ERROR in ./app/index.js

Module not found: Error: Can't resolve './app/test.js'

I've tried changing the file path to a relative one with no luck and I've also tried adding multiple entry points in the webpack config file but still no luck.

like image 315
Mr.Smithyyy Avatar asked May 23 '17 15:05

Mr.Smithyyy


People also ask

What is module not found error in react JS?

A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies. The module you're trying to import is in a different directory. The module you're trying to import has a different casing.

How do I import createRoot into react?

import React from 'react'; import ReactDOM from 'react-dom'; import { createRoot } from 'react-dom/client'; import Switch from './components/Switch'; const root = ReactDOM. createRoot(document. getElementById('root')); root. render( <React.


1 Answers

Posted as answer so that it can be marked as answered, from comment:

Your import path is wrong, it looks like you should change import test from './app/test.js'; to import test from './test.js';

like image 84
Joe Lissner Avatar answered Oct 21 '22 14:10

Joe Lissner