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

commonjs module under web_modules can not be load correctly in webpack 4. #7610

Closed
njleonzhang opened this issue Jun 27, 2018 · 4 comments
Closed

Comments

@njleonzhang
Copy link

Bug report

commonjs module under web_modules can not be load correctly in webpack 4.

What is the current behavior?

// webpack config

resolve: {
    modules: ['node_modules', 'web_modules'],
    ....
}
web_modules
   test-module
       index.js

import xxx from 'test-module'

// error: "export 'default' (imported as 'XXXX') was not found in 'message-box'

move the test-module folder to node_modules, the build pass.

node_modules
   test-module
       index.js

If the current behavior is a bug, please provide the steps to reproduce.
will try to make one later.

What is the expected behavior?
module under web_module should also work as node_modules

Other relevant information:
webpack version: 4.12.2
Node.js version: 8.7
Operating System: mac

@sokra
Copy link
Member

sokra commented Jun 27, 2018

Could you paste your module.rules?

@njleonzhang
Copy link
Author

module: {
    rules: [
      ...(config.dev.useEslint ? [createLintingRule()] : []),
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.pug$/,
        oneOf: [
          // this applies to <template lang="pug"> in Vue components
          {
            resourceQuery: /^\?vue/,
            use: ['pug-plain-loader']
          },
          // this applies to pug imports inside JavaScript
          {
            use: ['raw-loader', 'pug-plain-loader']
          }
        ]
      },
      {
        test:/\.(js|jsx)$/,
        loader: 'babel-loader',
        include: [
          resolve('src'),
          resolve('test'),
          resolve('node_modules/vue-echarts'),
          resolve('node_modules/resize-detector'),
          resolve('node_modules/webpack-dev-server/client')
        ]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('media/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.scss$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'sass-loader',
          {
            loader: 'sass-resources-loader',
            // global data for all components
            // this can be read from a scss file
            options: {
              resources: path.resolve(__dirname, '../src/assets/styles/variables.scss')
            }
          }
        ]
      },
      {
        test:/\.(js|jsx)$/,
        use:['babel-loader'],
        exclude:/node_modules/
      },
    ]
  },

@sokra
Copy link
Member

sokra commented Jun 28, 2018

Try removing the second instance of the babel loader:

      {
        test:/\.(js|jsx)$/,
        use:['babel-loader'],
        exclude:/node_modules/
      },

@njleonzhang
Copy link
Author

Tnx, it's so stupid. But why? the files under web_modules seems not related to the babel-loader.

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

No branches or pull requests

2 participants