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.

Transform in package.json on symlinked modules not working in npm3

See original GitHub issue

Environment: node@5.70 npm@3.75 browserify@13.0.0 babelify@7.2.0

Trying to build an app that worked with npm@2 and babelify@6 but having problems upgrading to npm@3 and babelify@7. Allow me to try and explain the problem.

  • In app/node_modules I have modules installed via npm install and local modules symlinked via npm link.
  • The local modules have browserify transforms specified in their package.json e.g -
...
  },
  "devDependencies": {
    "babel-preset-es2015": "^6.5.0",
    "babelify": "^7.2.0"
  },
  "browserify": {
    "transform": [
      [
        "babelify",
        {
          "presets": [
            "es2015"
          ]
        }
      ]
    ]
  }
...

Attempting to build I get error:

"Browserify Error: Couldn't find preset "es2015" relative to directory"

npm 3 has flattened out the dependency tree, so the babel-preset-es2015 the symlinked module needs are in the node_modules of app. According to the explanation by @substack here and this example here browserify should walk up the tree from the symlinked module to app and check in the node_modules there, but it doesn’t seem to be doing this.

My directory layout looks like this:

~/projects
  |-- app
    |-- entry.js (this file can see babel-preset just fine)
    |-- node_modules
       |-- babel-preset-es2015
       |-- my-module (symlink pointing at ~/projects/modules-shared/my-module)
          |-- index.js (we want babelify to transform this file)
  |-- modules-shared
     |-- my-module

If I install babel-preset-es2015 in the modules-shared folder, browserify finds the preset.

I get the impression from looking through other issues that this sort of problem has come up before and has long been fixed, so I wonder why I have the problem now.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Dec 6, 2018

.mjs - i’m not aware of anybody using .esm.

0reactions
laurencedormancommented, Dec 6, 2018

Yes thanks, I meant that @ljharb

Read more comments on GitHub >

github_iconTop Results From Across the Web

Browserify - transform in package.json on symlinked ...
Trying to build an app that worked with npm@2 and babelify@6 but having problems upgrading to npm@3 and babelify@7 . Allow me to...
Read more >
npm link doesn't play nice with peer dependencies #5875
Hi guys, Im on npm 3.3.3 and node 4.1.1 and still have problems with ... Cannot find peer dependency of symlinked module lerna/lerna#691....
Read more >
Why isn't the npm link command working? | Benjamin W Fox
Under the Hood. Running npm link creates a symlink (or 'symbolic link') from your global node_modules folder to the my-package directory (where ...
Read more >
plugin-transform-es2015-modules-commonjs didn't follow ...
This is not an issue with babel. import statements are all executed first, no matter where they appear in the code. Babel is...
Read more >
package.json
Don't use the same name as a core Node module. Don't put "js" or "node" in the name ... These are helpful for...
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