简体   繁体   中英

load node_modules with webpack

I want to load some modules, for instance:

  • moment
  • echarts

My package.json:

  • "echarts": "^3.1.10"
  • "moment": "^2.14.1"

but I have the next errors:

VM2282:1 Uncaught ReferenceError: moment is not defined(…)

My Webpack config:

{ test: /\\.js$/, loader: 'babel', exclude: /node_modules/ }

I do not know what happend. Can anybody help me?

Add to vendor.ts:

import 'echarts';
import 'moment';

and remove your code from webpack config. This works for me.

import { Component } from '@angular/core';
import * as moment from 'moment';
import '../../public/css/styles.css';
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent { 

  constructor(){
    let now = moment().format('LLLL');
    console.log(now)
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM