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

Not able to load custom node_modules directory via resolveLoader in Webpack 2 #3160

Closed
maxmilton opened this issue Oct 18, 2016 · 7 comments
Closed

Comments

@maxmilton
Copy link

I'm submitting a bug report

Webpack version: 2.1.0-beta.25
Language: TypeScript 2.0.3
Environment: Windows 7

Current behaviour:
If the node_modules directory is not in the same directory as source files, the build results in errors like:

ERROR in [default] C:\dev\project\path\app\app.module.ts:1:41
Cannot find module '@angular/core'.

ERROR in [default] C:\dev\project\path\app\app.module.ts:2:30
Cannot find module '@angular/platform-browser'.

Steps to reproduce:

  • Start with a base config from angular2-webpack-starter.
  • Move files so src directory is one directory up, like this example (simplified):
+-- project\
  +-- lib\
  |   +-- config\
  |   |  `-- webpack.common.js
  |   +-- node_modules\
  |   +-- package.json
  |   `-- webpack.config.js
  `-- src\
    +-- app\
    | `-- index.ts
    `-- main.browser.ts

It feels strange to me as I've tried all kinds of things with resolve.modules and resolveLoader.modules .etc but nothing works as expected. Am I simply going about this the wrong way or is this an issue with resolving in webpack 2?

I've put together a gist with my webpack.common.js here, resolveLoader starts on line 80.

@bruce-mitchell
Copy link

bruce-mitchell commented Oct 20, 2016

Hi,

I am experiencing the same issue at current and was about to log an issue before finding this post, I thought it may potentially be of use for me to post my issue as a comment on here for interest sake.

Is this considered a high priority issue, may I ask what the status of it is at current?

Webpack version:
2.1.0-beta.0

Environment:
Windows 10

Framework/Language:
Angular 2.0.1, Typescript 2.0.3

Current behavior:

I have a submodule which is used across all my projects as a global base for my build config.
It contains my webpack configuration and all my node modules which are used as part of my global system initialization.

This means that there are essentially 2 core "node_modules" directories, one being in the submodule which is used across all projects and the other being part of the project in question.

As per the webpack documentation, I am using the resolve.modules to define the path to the base node_modules in the submodule, I am then also defining the path to the node_modules in the current project for the project specific third party libraries. On building the solution, only the modules in the current project's node_modules are resolve, the modules in the base(shared) submodule are not resolved. For clarity, please see the file structure and corresponding webpack config below:

File Structure:

  • Project
    • SharedSubmodule
      • node_modules(These modules are not resolving)
      • Webpack.config
  • node_modules (These modules are resolving)

Webpack Config
resolve: {
modules: [
path.resolve('./SharedSubmodule/node_modules'),
path.resolve('./node_modules')
]

Expected/desired behavior:
I expect the root to be defined by the resolve.modules config and leverage the node search algorithm to resolve the alias provided either by the loaders or via an es6 import in one of the node_modules directories regardless of which of these node_modules the module exists in.

@ninjasort
Copy link

+1 Module build failed: Error: Couldn't find preset "latest" relative to directory with babel-loader

@corinnaerin
Copy link

I am having this same issue. Unfortunately my company's build system puts the node modules into a custom, deeply nested folder, and I don't have the power to change it to the standard node_modules directory in the project root to get around it.

Please advise when this problem will be fixed.

@mingxian
Copy link

mingxian commented Feb 4, 2017

I am having the same problem.

webpack version
2.2.1

Webpack Config

resolve: {
modules: [
path.resolve(__dirname, 'node_modules'),
'node_modules'
]
}

Error:

"ReferenceError: Unknown plugin "transform-react-jsx" specified in "base" at 0, attempted to resolve relative to ..."

"Couldn't find preset "latest" relative to directory ... "

Please advise when this problem will be fixed.

@ghost
Copy link

ghost commented Apr 18, 2017

maybe what you're looking for is something like:

module.exports = {
    dependencies: [
        path.join(__dirname, "..", "node_modules")
    ],
    entry: './src/main.js',
    output: {
    ...
    }
...
}

@epicallan
Copy link

I am having the same issue as the people above in a typescript project.

@nicolocodev just tried your suggestion and it didn't work with webpack 2.6.1

@alexander-akait
Copy link
Member

Closing due to inactivity. Please test with latest webpack version and feel free to reopen if still regressions. Thanks!

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

No branches or pull requests

8 participants