Giter Site home page Giter Site logo

Comments (33)

moreirayokoyama avatar moreirayokoyama commented on May 15, 2024 26

@Keats post on Stackoverflow has a good solution.

set the extensions property on Webpack resolve configuration like this:

webpackConfig.resolve.extensions = ['', '.js', '.coffee'] //ts, or anything else

That solved it for me.

from karma-webpack.

tiye avatar tiye commented on May 15, 2024 20

I think Webpack's error are really unfriendly... I tried for half an hour but failed to found out what's wrong when it gives this error.

from karma-webpack.

rcdmk avatar rcdmk commented on May 15, 2024 14

My problem was not changing the resolve.extensions option to include .jsx files.
I've added it to the end of my webpack.config.js file and it worked:

    // other configs...
    resolve: {
        extensions: [ '', '.js', '.jsx' ]
    }
};

from karma-webpack.

evandavis avatar evandavis commented on May 15, 2024 13

HOLY S#!T the issue for me was that I had an extra comma in my package.json file. Why is THAT hidden behind the --display-error-details flag?

from karma-webpack.

sethlivingston avatar sethlivingston commented on May 15, 2024 8

I was getting this error because my resolve.extensions extensions were missing dots. "jsx" should be ".jsx", for example.

from karma-webpack.

AndrewTHuang avatar AndrewTHuang commented on May 15, 2024 4

@eryue0220 What is the error you're receiving?

entry is expecting a string (or array of strings). Assuming entryFile.js is in the same directory as your webpack.config.js, it should read:

module.exports = {
    entry: './entryFile.js',
    output: {
        filename: 'outputFile.js'
    }
}

from karma-webpack.

fudini avatar fudini commented on May 15, 2024 1

I have the same problem.

from karma-webpack.

julesmoretti avatar julesmoretti commented on May 15, 2024 1

Yeah for me "--display-error-details" was a big help and then it turned out that some directory of mine was capitalized whereas my import scripts sources were not.

Also git was not seeing those changes locally so I ended up having to run this from my terminal to be able to commit the directory changes git config core.ignorecase false

from karma-webpack.

sokra avatar sokra commented on May 15, 2024

Have you added frameworks: ['webpack']?

from karma-webpack.

andrewk avatar andrewk commented on May 15, 2024

+1.

As per @sokra's question, yes we have webpack in the frameworks array.

Looking at the debug output:
ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' ./tests/run.js in /Users/andrew/Projects/99designs/projects

Something (webpack preloader?) is assuming the files are relative to the path, when they are not. eg: in the above scenario, the file it cannot resolve is at /Users/andrew/Projects/99designs/projects/assets/tests/run.js, but as of karma-webpack 1.4 the resolution is not working, despite webpack.resolve.root being set to /Users/andrew/Projects/99designs/projects/assets.

Here is all karma and webpack config for the codebase I'm currently looking at -- https://gist.github.com/andrewk/b175483507d1c2307b25

from karma-webpack.

ebi avatar ebi commented on May 15, 2024

Having the same issue even with webpack in frameworks, seems to be related to resolve root too.

from karma-webpack.

sokra avatar sokra commented on May 15, 2024

I don't think this is wrong. karma resolves the files array and doesn't know about resolve.root. It's not expected that entries in the files array resolve in moduleDirectories or in resolve.root. files is handled by karma.

from karma-webpack.

ebi avatar ebi commented on May 15, 2024

It's working again 1.5.0

I think if this behaviour is / would have been intentional it should be a new major version since it's a BC break.

from karma-webpack.

quidmonkey avatar quidmonkey commented on May 15, 2024

I'm also seeing this error on 1.5.1, and I'm unable to make heads or tails of it. For reference, my code is here - you'll need to run npm install and then gulp test.

My directory structure looks like this:

src
├── components
│   ├── content.jsx
│   ├── createItem.jsx
│   ├── createList.jsx
│   ├── deleteList.jsx
│   ├── header.jsx
│   ├── item.jsx
│   ├── list.jsx
│   ├── login.jsx
│   ├── mainMenu.jsx
│   └── notFound.jsx
├── config.js
├── index.jsx
├── mixins
│   └── forceFireLoginMixin.jsx
└── styles
    └── elisse.styl

test
├── karma.conf.js
├── specs
│   ├── headerSpec.js
│   └── testSpec.js
└── tests.webpack.js

My karma.conf.js looks like this:

'use strict';

module.exports = function (config) {
  config.set({
    browsers: ['PhantomJS'],
    frameworks: ['jasmine'],
    singleRun: true,
    files: [
      '../src/**/*.{js,jsx}',
      'specs/**/*.js'
    ],
    preprocessors: {
      '../src/**/*.{js,jsx}': ['webpack', 'sourcemap'],
      'specs/**/*.js': ['webpack', 'sourcemap']
    },
    reporters: ['spec'],
    webpack: {
      devtool: 'inline-source-map', // in-line source maps instead of the default
      module: {
        loaders: [
          {
            test: /\.(js|jsx)$/,
            exclude: /(node_modules|bower_components)/,
            loader: 'babel-loader'
          }
        ]
      },
      resolve: {
        // tell webpack to look for required files in bower and node
        modulesDirectories: [
          'bower_components',
          'node_modules'
        ],
      }
    },
    webpackServer: {
      noInfo: false
    },
    colors: true,
  });
};

When I run karma, I get the following:

Hash: 8344a6c0a9b3c44a5636
Version: webpack 1.9.10
Time: 7ms
webpack: bundle is now VALID.
webpack: bundle is now INVALID.
Hash: 3d83204cffc24f629e2e
Version: webpack 1.9.10
Time: 689ms
                                Asset     Size  Chunks             Chunk Names
     ../src/components/createList.jsx  3.56 kB       7  [emitted]  ../src/components/createList.jsx
                  specs/headerSpec.js  1.66 MB       0  [emitted]  specs/headerSpec.js
         ../src/components/header.jsx  2.78 kB       2  [emitted]  ../src/components/header.jsx
       ../src/components/notFound.jsx  1.87 kB       3  [emitted]  ../src/components/notFound.jsx
                     ../src/config.js     4 kB       4  [emitted]  ../src/config.js
        ../src/components/content.jsx  2.81 kB       5  [emitted]  ../src/components/content.jsx
     ../src/components/createItem.jsx  3.58 kB       6  [emitted]  ../src/components/createItem.jsx
                    specs/testSpec.js  4.21 kB       1  [emitted]  specs/testSpec.js
     ../src/components/deleteList.jsx  3.27 kB       8  [emitted]  ../src/components/deleteList.jsx
           ../src/components/item.jsx  3.66 kB       9  [emitted]  ../src/components/item.jsx
           ../src/components/list.jsx  4.95 kB      10  [emitted]  ../src/components/list.jsx
       ../src/components/mainMenu.jsx  4.53 kB      11  [emitted]  ../src/components/mainMenu.jsx
                     ../src/index.jsx  5.15 kB      12  [emitted]  ../src/index.jsx
          ../src/components/login.jsx  6.19 kB      13  [emitted]  ../src/components/login.jsx
../src/mixins/forceFireLoginMixin.jsx   2.8 kB      14  [emitted]  ../src/mixins/forceFireLoginMixin.jsx
chunk    {0} specs/headerSpec.js (specs/headerSpec.js) 627 kB
    [0] ./test/specs/headerSpec.js 748 bytes {0} [built]
    [1] ./dev/components/header.js 1.26 kB {0} [built]
    [2] ./bower_components/react/react-with-addons.js 625 kB {0} [built]
chunk    {1} specs/testSpec.js (specs/testSpec.js) 143 bytes [rendered]
    [0] ./test/specs/testSpec.js 143 bytes {1} [built]
chunk    {2} ../src/components/header.jsx (../src/components/header.jsx) 1.31 kB [rendered]
    [0] ./src/components/header.jsx 1.31 kB {2} [built]
chunk    {3} ../src/components/notFound.jsx (../src/components/notFound.jsx) 424 bytes [rendered]
    [0] ./src/components/notFound.jsx 424 bytes {3} [built]
chunk    {4} ../src/config.js (../src/config.js) 145 bytes [rendered]
    [0] ./src/config.js 145 bytes {4} [built]
chunk    {5} ../src/components/content.jsx (../src/components/content.jsx) 1.22 kB [rendered]
    [0] ./src/components/content.jsx 1.22 kB {5} [built] [1 error]
chunk    {6} ../src/components/createItem.jsx (../src/components/createItem.jsx) 1.97 kB [rendered]
    [0] ./src/components/createItem.jsx 1.97 kB {6} [built] [1 error]
chunk    {7} ../src/components/createList.jsx (../src/components/createList.jsx) 1.94 kB [rendered]
    [0] ./src/components/createList.jsx 1.94 kB {7} [built] [1 error]
chunk    {8} ../src/components/deleteList.jsx (../src/components/deleteList.jsx) 1.66 kB [rendered]
    [0] ./src/components/deleteList.jsx 1.66 kB {8} [built] [1 error]
chunk    {9} ../src/components/item.jsx (../src/components/item.jsx) 2.04 kB [rendered]
    [0] ./src/components/item.jsx 2.04 kB {9} [built] [1 error]
chunk   {10} ../src/components/list.jsx (../src/components/list.jsx) 3.3 kB [rendered]
    [0] ./src/components/list.jsx 3.3 kB {10} [built] [1 error]
chunk   {11} ../src/components/mainMenu.jsx (../src/components/mainMenu.jsx) 2.89 kB [rendered]
    [0] ./src/components/mainMenu.jsx 2.89 kB {11} [built] [1 error]
chunk   {12} ../src/index.jsx (../src/index.jsx) 2.21 kB [rendered]
    [0] ./src/index.jsx 2.21 kB {12} [built] [11 errors]
chunk   {13} ../src/components/login.jsx (../src/components/login.jsx) 4.52 kB [rendered]
    [0] ./src/components/login.jsx 4.52 kB {13} [built] [1 error]
chunk   {14} ../src/mixins/forceFireLoginMixin.jsx (../src/mixins/forceFireLoginMixin.jsx) 1.21 kB [rendered]
    [0] ./src/mixins/forceFireLoginMixin.jsx 1.21 kB {14} [built] [1 error]

WARNING in ./bower_components/react/react-with-addons.js
Critical dependencies:
4:436-443 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./bower_components/react/react-with-addons.js 4:436-443

ERROR in ./src/components/content.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ../mixins/forceFireLoginMixin in /Users/quidmonkey/Development/research/elisse/src/components
 @ ./src/components/content.jsx 7:33-73

ERROR in ./src/components/createItem.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ../mixins/forceFireLoginMixin in /Users/quidmonkey/Development/research/elisse/src/components
 @ ./src/components/createItem.jsx 7:33-73

ERROR in ./src/components/createList.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ../mixins/forceFireLoginMixin in /Users/quidmonkey/Development/research/elisse/src/components
 @ ./src/components/createList.jsx 7:33-73

ERROR in ./src/components/deleteList.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ../mixins/forceFireLoginMixin in /Users/quidmonkey/Development/research/elisse/src/components
 @ ./src/components/deleteList.jsx 7:33-73

ERROR in ./src/components/item.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ../mixins/forceFireLoginMixin in /Users/quidmonkey/Development/research/elisse/src/components
 @ ./src/components/item.jsx 7:33-73

ERROR in ./src/components/list.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ../mixins/forceFireLoginMixin in /Users/quidmonkey/Development/research/elisse/src/components
 @ ./src/components/list.jsx 7:33-73

ERROR in ./src/components/mainMenu.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ../mixins/forceFireLoginMixin in /Users/quidmonkey/Development/research/elisse/src/components
 @ ./src/components/mainMenu.jsx 7:33-73

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/header' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 3:24-52

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/content' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 5:25-54

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/mainMenu' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 7:26-56

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/login' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 9:23-50

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/createList' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 11:28-60

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/list' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 13:22-48

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/deleteList' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 15:28-60

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/createItem' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 17:28-60

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/item' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 19:22-48

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'components/notFound' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 21:26-56

ERROR in ./src/index.jsx
Module not found: Error: Cannot resolve module 'mixins/forceFireLoginMixin' in /Users/quidmonkey/Development/research/elisse/src
 @ ./src/index.jsx 23:33-70

ERROR in ./src/components/login.jsx
Module not found: Error: a dependency to an entry point is not allowed
 @ ./src/components/login.jsx 7:14-34

ERROR in ./src/mixins/forceFireLoginMixin.jsx
Module not found: Error: a dependency to an entry point is not allowed
 @ ./src/mixins/forceFireLoginMixin.jsx 7:14-34
webpack: bundle is now VALID.

This error makes no sense. As you can see by my directory structure, the pathing is correct. Ideas?

from karma-webpack.

Keats avatar Keats commented on May 15, 2024

I'm getting something similar (posted a question on stackoverflow: http://stackoverflow.com/questions/30931713/webpack-karma-cannot-resolve-local-import) , I don't understand this issue either

@quidmonkey did you figure out the issue?

from karma-webpack.

evandavis avatar evandavis commented on May 15, 2024

Getting the same issue; I can't understand what the error is supposed to mean. It's telling me that a file with a correct path cannot be found. Anyone?

from karma-webpack.

sokra avatar sokra commented on May 15, 2024

@evandavis Sorry. Invalid package.json is propably rar... Nobody made a nice custom error for this...

from karma-webpack.

DanielHeath avatar DanielHeath commented on May 15, 2024

I just spent an hour or two trying to debug this completely misleading error message :-(

from karma-webpack.

DanielHeath avatar DanielHeath commented on May 15, 2024

Why is this even reading package.json? What happens if you don't use npm to manage your dependencies?

from karma-webpack.

sokra avatar sokra commented on May 15, 2024

Why is this even reading package.json?

because there could be a browser field which defines overwrites.

What happens if you don't use npm to manage your dependencies?

It's fine when it doesn't find a file.

from karma-webpack.

sebald avatar sebald commented on May 15, 2024

@moreirayokoyama Thanks! ...was using a striped down Webpack configuration to run tests and forgot about the resolve property.

from karma-webpack.

dignifiedquire avatar dignifiedquire commented on May 15, 2024

@sebald get your game together 😛

from karma-webpack.

sebald avatar sebald commented on May 15, 2024

@dignifiedquire http://www.reactiongifs.com/r/hildc.gif

from karma-webpack.

jpierson avatar jpierson commented on May 15, 2024

@sethlivingston Thank you, I had a similar long standing issue trying to get jsx, ts, and tsx extensions to be resolved correctly and the missing dot apparently was the reason.

from karma-webpack.

eryue0220 avatar eryue0220 commented on May 15, 2024

Sadly, in webpack 1.12.11 the--allow-incompatible-update has remove, and the problem is still existing. And I write as follow, it worked:

module.exports = {
    entry: [entryFile.js],
    output: {
        filename: 'outputFile.js'
    }
}

But, it throw another error....

from karma-webpack.

jiw29 avatar jiw29 commented on May 15, 2024

resolve by this : http://webpack.github.io/docs/configuration.html#resolve-extensions

from karma-webpack.

408796571 avatar 408796571 commented on May 15, 2024
  1. Restart Terminal(Mac) or whatever shell in your environment.
  2. Add FIXFIX in package.json like this:
    "scripts": { "FIXFIX": "webpack --progress --profile --colors --display-error-details --display-cached", },
  3. Run this: (Yes, with sudo!)
    sudo node run FIXFIX
  4. Now run with your normal build see if it fixed.

from karma-webpack.

joshim5 avatar joshim5 commented on May 15, 2024

Just spent an hour sourcing this problem - was also getting Error: Entry module not found: Error: Cannot resolve 'file' or 'directory' even though problem was an extra comma in package.json. Can we get better error handling? Wouldn't be surprised if this issue was more widespread than expected here...

from karma-webpack.

alalicon577 avatar alalicon577 commented on May 15, 2024

i recently encountered this. The index.html was in another directory. So I just need to resolve the path and it worked.

from karma-webpack.

 avatar commented on May 15, 2024

i recently encountered this

from karma-webpack.

LuckyWenTing avatar LuckyWenTing commented on May 15, 2024

i fixed this problem by setting the working directory to the your_project\src\server instead of your_project\src\server\bin

from karma-webpack.

tewshi avatar tewshi commented on May 15, 2024

@eryue0220 What is the error you're receiving?

entry is expecting a string (or array of strings). Assuming entryFile.js is in the same directory as your webpack.config.js, it should read:

module.exports = {
    entry: './entryFile.js',
    output: {
        filename: 'outputFile.js'
    }
}

This solved my problem... thanks, my entry was missing.

from karma-webpack.

Liuyll avatar Liuyll commented on May 15, 2024

I was getting this error because my resolve.extensions extensions were missing dots. "jsx" should be ".jsx", for example.

thanks,i ignore the symbol ',' ...

from karma-webpack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.