简体   繁体   English

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

[英]Webpack: cannot reach my imported module

The problem: 问题:

  1. I import a .js module in my entry file. 我在输入文件中导入了一个.js模块。
  2. It is included in the bundle.js. 它包含在bundle.js中。
  3. It is still undefined and cannot figure out why. 它仍然是未定义的,无法找出原因。

My webpack config file: 我的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: 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!");
}

Outputs: "Still not reachable" 输出:“仍然无法到达”

  • Lodash and axios work as expected. Lodash和axios可以正常工作。
  • Vue + Vue Component works. Vue + Vue组件有效。
  • UrlFunctions module is seemingly imported into the bundle.js, however it says it is not declared. 看似UrlFunctions模块已导入bundle.js,但是它没有声明。

excerpt from bundle.js: 摘自bundle.js:

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

In the module file it's correctly exported. 在模块文件中,它已正确导出。

I don't have one clue. 我没有任何线索。

I have created a single file like: 我创建了一个文件,例如:

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

I tried to import that in my entry file, the signup.js and this also wasn't declared! 我试图将其导入到我的输入文件signup.js中,但也未声明! ... ...

npm-deps: 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"
}

It seems that for some reason when exporting a module: 似乎出于某种原因导出模块时:

export myModule; // nOK

export { myModule }; // nOK

export default myModule; // OK!

module.exports = myModule; // OK!

  • I tried to add include the folder for Babel from I am importing the Module from: didn't help. 我试图从导入模块的位置添加include Babel的文件夹:没有帮助。
  • Reinstalled node and npm completely, switched to Webpack 2: wasn't the problem. 完全重新安装了node和npm,切换到Webpack 2:并不是问题。

It's welcome if you have any insight on that. 如果您对此有任何见解,欢迎您。

暂无
暂无

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

相关问题 webpack 导入的模块不是构造函数 - webpack imported module is not a constructor 类型错误:Webpack 导入的模块不是 function - TypeError: Webpack imported module is not a function 类型错误:无法解构“react__WEBPACK_IMPORTED_MODULE_0__.state”的属性“jobArray”,因为它未定义 - TypeError: Cannot destructure property 'jobArray' of 'react__WEBPACK_IMPORTED_MODULE_0__.state' as it is undefined 为什么我无法解构“(0,_contexts_AuthContext__WEBPACK_IMPORTED_MODULE_1__.useAuth)(...)”的属性“登录”,因为它是未定义的 - Why am I getting Cannot destructure property 'login' of '(0 , _contexts_AuthContext__WEBPACK_IMPORTED_MODULE_1__.useAuth)(...)' as it is undefined TypeError:无法解构“(0,react__WEBPACK_IMPORTED_MODULE_0__.useContext)(...)”的属性“setAppState”,因为它未定义 - TypeError: Cannot destructure property 'setAppState' of '(0 , react__WEBPACK_IMPORTED_MODULE_0__.useContext)(...)' as it is undefined UnhandledThrownError,无法解构“(0.react_redux__WEBPACK_IMPORTED_MODULE_2__.useSelector)(...)”的属性“类别”,因为它未定义 - UnhandledThrownError! Cannot destructure property 'categories'of '(0 , react_redux__WEBPACK_IMPORTED_MODULE_2__.useSelector)(...)' as it is undefined 找不到模块“。” - webpack - Cannot find module “.” - webpack Webpack - 无法解析模块 - Webpack - Cannot resolve module Webpack 找不到模块 - Webpack cannot find module Webpack 2:无法解析模块 - Webpack 2: cannot resolve module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM