Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function not found due to wrong path #52

Closed
PascalAOMS opened this issue Jan 22, 2017 · 8 comments
Closed

Function not found due to wrong path #52

PascalAOMS opened this issue Jan 22, 2017 · 8 comments

Comments

@PascalAOMS
Copy link

When installing via NPM or in my case Yarn it does not find the correct file to import.

import jump from 'jump.js' does not find anything since there is no index.js installed.

Editing the path to ''jump.js/dist/jump' does work.

Furthermore the downloaded files are all in ES5. There is no src folder at all.

@PascalAOMS PascalAOMS changed the title Function not found Function not found due to wrong path Jan 22, 2017
@callmecavs
Copy link
Owner

callmecavs commented Jan 24, 2017

@PascalAOMS no index.js is required, neither are src files. the downloaded files should be as they are (ES5), otherwise your build process would have to transpile your node_modules, which is undesirable and unmaintainable, because of the likelihood of library authors using different babel configs.

all the fields in the package.json that tell bundlers where to get the file from point to the dist folder. those dist files are created in the prepublish hook.

npm and yarn are only used to install packages - its likely a problem with your bundler config (browserify, webpack, etc) thats causing the failure to import. without seeing more of your config, its hard to say for sure, but im almost 100% positive this is related to that

@PascalAOMS
Copy link
Author

Thank you very much for the explanation.

@callmecavs
Copy link
Owner

callmecavs commented Jan 24, 2017

@PascalAOMS no problem. feel free to post your webpack/browserify config - id be happy to take a look

@PascalAOMS
Copy link
Author

PascalAOMS commented Jan 24, 2017

You can find my webpack.config.js here.

Thanks!

@callmecavs
Copy link
Owner

callmecavs commented Jan 24, 2017

@PascalAOMS my guess is that something with your directory structure is throwing off webpack and preventing it from finding your node_modules.

the way you're aliasing vue looks like its because of a similar problem you had importing it. try adding a root to your resolve object, as in the following, and hopefully you wont need aliases (unless those are there for a different reason):

resolve: {
  // point this to the root folder of your project
  // node_modules should be inside of the folder this points to
  root:  path.resolve(__dirname, './relative/path'),
  
  alias: {
    // your existing aliases might not be needed anymore
    // if jump.js works, try removing the vue alias
  }
}

let me know if that helps

@PascalAOMS
Copy link
Author

I am using Webpack 2. You gave me a good tip with root though.

The equivalent would be

resolve: {
        modules: ['src', 'node_modules']
}

But that does not seem to work either.

@callmecavs
Copy link
Owner

callmecavs commented Jan 24, 2017

@PascalAOMS im stumped. this is my boilerplate for webpack 2, itll generate a directory for you. using that structure, everything works for me without even specifying the root directory or modules directory 🤕

here's a link to the webpack config (its in the template folder)

@PascalAOMS
Copy link
Author

Using const jump = require('jump.js').default works as well.

No idea why though. Yea...

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

No branches or pull requests

2 participants