M
M
Maxim Ivanov2017-01-09 17:18:33
webpack
Maxim Ivanov, 2017-01-09 17:18:33

How to allow libraries to be included in a specific path for node_modules via webpack2?

In my ui-util directory, webpack is launched with the key source=
path_to_resources_webpack.config.js

config.entry = {
    'polyfills': `${SOURCE}/polyfills.ts`,
    'vendor':  `${SOURCE}/vendor.ts`,
    'app': `${SOURCE}//main.ts`
  };

The sources themselves have library connections, for example
import {enableProdMode} from "@angular/core";
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";

But the problem is that the "@angular/core" libraries are no longer found, and of course (since node_modules is in the ui-util directory locally, just like webpack runs locally)
But the resources are not local, and how to forward the path to them for them node_modules? So that he connects from there?
Added config file
config.resolve = {
        extensions: ['.ts', '.js', '.json', '.css', '.scss', '.html'],
        modules: [
            path.resolve(__dirname, "node_modules"),
        ]
    };

libraries began to be easily connected in the resource directory, but some are not, but they are not connected in nested ones
.
├── app
│   ├── app.component.html
│   ├── app.component.scss
│   ├── app.component.ts
│   ├── app.module.ts
│   └── directives
│       └── materialize-select.directive.ts
├── main.ts
├── polyfills.ts
├── settings.json
└── vendor.ts

Some connect, but some don't, it's very strange and it's not clear how to fix it
ERROR in [at-loader] ../auth/src/main/resources/webapp/source/app/app.component.ts:1:81 
    Cannot find module '@angular/core'.

ERROR in [at-loader] ../auth/src/main/resources/webapp/source/app/app.component.ts:2:50 
    Cannot find module '@angular/forms'.

ERROR in [at-loader] ../auth/src/main/resources/webapp/source/app/app.module.ts:1:24 
    Cannot find module '@angular/core'.

ERROR in [at-loader] ../auth/src/main/resources/webapp/source/app/app.module.ts:2:29 
    Cannot find module '@angular/platform-browser'.

ERROR in [at-loader] ../auth/src/main/resources/webapp/source/app/app.module.ts:3:26 
    Cannot find module '@angular/http'.

ERROR in [at-loader] ../auth/src/main/resources/webapp/source/app/app.module.ts:4:48 
    Cannot find module '@angular/forms'.

ERROR in [at-loader] ../auth/src/main/resources/webapp/source/app/directives/materialize-select.directive.ts:1:59 
    Cannot find module '@angular/core'.

ERROR in [at-loader] ../auth/src/main/resources/webapp/source/main.ts:1:30 
    Cannot find module '@angular/core'.

ERROR in [at-loader] ../auth/src/main/resources/webapp/source/main.ts:2:38 
    Cannot find module '@angular/platform-browser-dynamic'.

At the same time, these libraries are definitely present in node_modules

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question