繁体   English   中英

Webpack:无法访问我导入的模块

[英]Webpack: cannot reach my imported module

问题:

  1. 我在输入文件中导入了一个.js模块。
  2. 它包含在bundle.js中。
  3. 它仍然是未定义的,无法找出原因。

我的webpack配置文件:

module.exports = {
  entry: {
    // Entry points for pages:
    signup: './signup.js',
    activate: './activate.js'
  },
  output: {
    path: __dirname + '/build',
    filename: '[name].page.bundle.js',
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel',
        exclude: /node_modules/,
      },
      {
        test: /\.json$/,
        loader: 'json',
      },
      {
        test: /\.vue$/,
        loader: 'vue',
      }
    ],
  },
  vue: {
    loaders: {
      js: 'babel',
    }
  },
  resolve: {
  alias: {vue: 'vue/dist/vue.js'}
  },
};

Signup.js:

import Vue from 'vue';
import _ from 'lodash';
import axios from 'axios';

import Signup from './vue-components/page-signup-form.vue';

import UrlFunctions from './js/urlFunctions';


if (typeof UrlFunctions === "undefined") {
  console.log("Still not reachable!");
}

输出:“仍然无法到达”

  • Lodash和axios可以正常工作。
  • Vue + Vue组件有效。
  • 看似UrlFunctions模块已导入bundle.js,但是它没有声明。

摘自bundle.js:

...
var UrlFunctions = exports.UrlFunctions = {
...

在模块文件中,它已正确导出。

我没有任何线索。

我创建了一个文件,例如:

// sg.js
export var sg = "something";

我试图将其导入到我的输入文件signup.js中,但也未声明! ...

npm-deps:

"devDependencies": {
  "babel-core": "^6.20.0",
  "babel-loader": "^6.2.9",
  "babel-plugin-transform-runtime": "^6.15.0",
  "babel-preset-es2015": "^6.18.0",
  "babel-runtime": "^6.20.0",
  "css-loader": "^0.26.1",
  "json-loader": "^0.5.4",
  "script-loader": "^0.7.0",
  "vue-loader": "^10.0.2",
  "vue-template-compiler": "^2.1.6",
  "webpack": "^1.14.0"
},
  "dependencies": {
  "axios": "^0.15.3",
  "lodash": "^4.17.2",
  "vue": "^2.1.6"
}

似乎出于某种原因导出模块时:

export myModule; // nOK

export { myModule }; // nOK

export default myModule; // OK!

module.exports = myModule; // OK!

  • 我试图从导入模块的位置添加include Babel的文件夹:没有帮助。
  • 完全重新安装了node和npm,切换到Webpack 2:并不是问题。

如果您对此有任何见解,欢迎您。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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