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

Cannot find module external dependency #16

Closed
dlebedynskyi opened this issue Nov 26, 2014 · 7 comments
Closed

Cannot find module external dependency #16

dlebedynskyi opened this issue Nov 26, 2014 · 7 comments

Comments

@dlebedynskyi
Copy link

Hi,
Im keep getting error with external dependencies.
My best guess is that it is related someway to folder structure and not using relative
as example I have

  • build
    • test
    • umd
  • node_modules

when I try to run command both from node root or cmd

[folder_path]>pure-cjs -i build/test/index.js -o build/umd/index.js -e index
Building...
Error: Cannot find module 'lodash' from '[folder_path]\build\test'
at Function.module.exports as sync
at Object.exports.getNodePath (C:\Users[username]\AppData\Roaming\npm\node_modules\pure-cjs\lib\pathUtils.js:20:43)
at Replacer.getDependency (C:\Users[username]\AppData\Roaming\npm\node_modules\pure-cjs\lib\replacer.js:34:32)

or if from node as gulp task

Error: Cannot find module 'lodash' from ''[folder_path]'
at Function.module.exports as sync
at Object.exports.getNodePath ('[folder_path]\node_modules\pure-cjs\lib\pathUtils.js:20:43)
at ReplacerMap. ('[folder_path]\node_modules\pure-cjs\lib\replacerMap.js:13:17)
at Array.reduce (native)

Can you help with this? Running without externals work well for me.

@dlebedynskyi
Copy link
Author

Looks like pure-cjs is looking for external dependency to be present in node_modules. It seems not required for me since this dependency is eventually not gonna be included in build file.

@QuentinRoy
Copy link

I run into the same kind of issues.
I don't get why pure-cjs requires me to have the external dependencies in node_modules.

@RReverser
Copy link
Owner

Because pure-cjs relies on full paths in order to generate really small overhead by replacing every single require('...path...') call into _require(intId). So it needs to know the structure of external dependencies as well in order to link, for example, require('myModule') and require('myModule/lib/index') to the same id and same external variable and reuse it whenever needed.

@QuentinRoy
Copy link

Oh I understand now.. Thank you for your short answer.
I have to admit I still find it a little bit restrictive. Personally I still find it a little bit strange to install a browser-only lib with npm.. I usually prefer bower for that. Some libs may even not provide a package.json file. Why couldn't I use them?
Why not just checking for the 'myModule' prefix in 'myModule/lib/index'? Isn't it sufficient to associate the id? I could give it a try when I have some time.

@QuentinRoy
Copy link

Sorry about these critics, I still really like pure-cjs. Best compromise I found. Great work! Thank you.

@RReverser
Copy link
Owner

Why not just checking for the 'myModule' prefix in 'myModule/lib/index'? Isn't it sufficient to associate the id?

Unfortunately no, because actual source file is determined by main field of package.json and can be set to any path. Other source files under the module's folder should not be considered aliases to the module's name itself as user should be able to access them separately.

@QuentinRoy
Copy link

OK I see. In my opinion, it still think it could be great if this could be disabled (it could mean not associating for sub modules).
E.g. it could exists a checkSub flag defaulted to true for each external. Someone could then do:

external: {
      mylib: { global: 'mylib', amd: 'mylib', checkSub: false }
}

In that case no need to look for the mylib module. And if someone does require('mylib/mysublib') we rely on the usual mechanism (or it must be added independently in the external definitions).

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

3 participants