question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

npm module doesn't require folder_name

See original GitHub issue

Description

I install and require elasticsearch in my code, but the compiled js errored with

Uncaught Error: Cannot find module 'elasticsearch/src/lib/loggers' from 'elasticsearch/src/lib/log.js'

Expected behavior

It should require node_modules/elasticsearch/src/lib/loggers/index.js

Actual behavior

As error message.

demo project run npm start and open development tool console for the error message.

If I modify the module, fix the require syntax to require("./loggers/index.js"), it success and error at next folder requirement.

I’ve tried to alter the brunch config’s like

javascripts: {
      joinTo: {
        'app.js': /^(app|node_modules)/
      }
}

but still no luck.

Environment

  1. Brunch: 2.9.1
  2. Node: v7.0.0
  3. NPM: 4.0.1
  4. Operating system: macOS 10.12.1

package.json contents

{
  "name": "brunch-app",
  "version": "0.1.0",
  "scripts": {
    "start": "brunch watch --server",
  },
  "dependencies": {
    "elasticsearch": "^12.0.1"
  },
  "devDependencies": {
    "auto-reload-brunch": "^2.0.0",
    "brunch": "^2.0.0",
    "clean-css-brunch": "^2.0.0",
    "css-brunch": "^2.0.0",
    "javascript-brunch": "^2.0.0",
    "uglify-js-brunch": "^2.0.0"
  }
}

brunch config contents

exports.files = {
  javascripts: {joinTo: 'app.js'},
  stylesheets: {joinTo: 'app.css'},
  templates: {joinTo: 'app.js'},
  plugins: {
    babel: {}
  },
  npm: {
    enabled: true
  }
};

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
taiansucommented, Feb 10, 2018

@rafbgarcia Ah no, I just switch to other packaging tools after that.

0reactions
conradfrcommented, Mar 27, 2018

I just lost many hours I guess related to this. Using Brunch because it’s by default with Phoenix but I just can’t get a simple npm module that require some lodash functions to work properly (unless I import them myself in my app.js …)

And this issue is open for a year and a half ? I was excited to use Brunch because it seems simple and I hate Webpack but I guess I’ve no choice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing files in node package without including dist folder ...
So here I have to specify the dist folder name in import path. Is there way to specify just 'my-lib/foo' omitting dist folder...
Read more >
folders - npm Docs
When installing locally, this means that you can require("packagename") to load its main module, or require("packagename/lib/path/to/sub/module") to load ...
Read more >
Requiring modules in Node.js: Everything you need to know
Requiring a folder. Modules don't have to be files. We can also create a find-me folder under node_modules and place an ...
Read more >
CommonJS modules | Node.js v19.3.0 Documentation
The semantics of the Node.js require() function were designed to be general enough to support reasonable directory structures. Package manager programs such as ......
Read more >
Modules required from outside of root directory does not find ...
Yes. If you do require('foo') , then it looks node_modules/foo first in the directory of the module you're requiring from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found