webpack-contrib / imports-loader

Imports Loader
MIT License
520 stars 63 forks source link

Can't resolve 'window' in 'project/node_modules/jquery/dist' #122

Closed Hongbusi closed 2 years ago

Hongbusi commented 2 years ago

Bug report

Can't resolve 'window' in 'project/node_modules/jquery/dist'
Can't resolve 'var define = false' in 'project/node_modules/jquery/dist'

Actual Behavior

In webpack@5.68.0 + imports-loader@3.1.1 can not work.

In webpack.config.js:

{
    test: new RegExp(`(${regExp.join('|')})$`),
    use: [
      {
        loader: 'imports-loader',
        options: {
          additionalCode: 'var define = false; var module = false; var exports = false;',
          wrapper: 'window'
        }
      }
    ]
 }

In webpack@4.41.2 + imports-loader@0.8.0 normal work.

In webpack.config.js:

{
    test: new RegExp(`(${regExp.join('|')})$`),
    loader: 'imports-loader?define=>false&module=>false&exports=>false&this=>window',
}

Please paste the results of npx webpack-cli info here, and mention other relevant information

  System:
    OS: macOS 12.0.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
    Memory: 595.60 MB / 8.00 GB
  Binaries:
    Node: 12.22.7 - ~/.nvm/versions/node/v12.22.7/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.3 - ~/.nvm/versions/node/v12.22.7/bin/npm
  Browsers:
    Chrome: 98.0.4758.80
    Firefox: 95.0.2
    Safari: 15.1
  Packages:
    es-webpack-engine: ^4.6.0 => 5.0.0
alexander-akait commented 2 years ago

Can you provide reproducible example? I think you try to wrapper already wrapped function

Hongbusi commented 2 years ago

Can you provide reproducible example? I think you try to wrapper already wrapped function

Thanks for your answer, I think so too.

But one thing I can't understand is that the same code, why is it normal in v0.8.0, but the latest version will have this problem?

alexander-akait commented 2 years ago

Because we do refactor and change some logic

Hongbusi commented 2 years ago

Because we do refactor and change some logic

To upgrade to the latest version, are there any good solutions or ideas for this problem?

Thank you!

alexander-akait commented 2 years ago

Please provide reproducible example, I don't know your code, so hard to say what is wrong

Hongbusi commented 2 years ago

Please provide reproducible example, I don't know your code, so hard to say what is wrong

Project configuration:

Webpack configuration:

Old webpack configuration:

alexander-akait commented 2 years ago

Why you don't parse jquery?

Hongbusi commented 2 years ago

Why you don't parse jquery?

All noParse modules in the configuration file(https://github.com/edusoho/edusoho/blob/master/webpack.config.js#L41) will report the above error.

alexander-akait commented 2 years ago

How you run webpack? I can't found scripts

Hongbusi commented 2 years ago

How you run webpack? I can't found scripts

By executing node api:

alexander-akait commented 2 years ago

Sorry, I can't run your configuration without problems, I got:

[webpack-cli] Failed to load '/home/evilebottnawi/IdeaProjects/es-webpack-engine/src/webpack.dev.js' config
[webpack-cli] Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
 - options.patterns should be a non-empty array.

Using webpack --config src/webpack.dev.js, please provide steps to reproducible the problem

Hongbusi commented 2 years ago

Thanks for taking the time to help me figure this out.

Steps to reproduce:

  1. Download edusoho, install dependencies.
  2. Download es-webpack-engine, install dependencies.
  3. Connect edusho to es-webpack-engine via npm link.
  4. Modify the path where script dev in edusoho introduces es-webpack-engine (/dist/ -> /src/).
  5. Execute yarn dev.
  6. Wait a moment, you can see the error message.
Hongbusi commented 2 years ago

Sorry to bother you again, might need your help to provide some ideas. @alexander-akait

alexander-akait commented 2 years ago

@Hongbusi Can you reduce complex of the reproducible? I still can't run your example

Hongbusi commented 2 years ago

Solved this problem in other ways. Also thank you very much for the help you provided me. @alexander-akait