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

dynamic resolve fails #277

Closed
bfulop opened this issue Feb 12, 2019 · 5 comments
Closed

dynamic resolve fails #277

bfulop opened this issue Feb 12, 2019 · 5 comments

Comments

@bfulop
Copy link

bfulop commented Feb 12, 2019

Uglify JS (which is a dependency of another lib I'm using) uses this import format

var FILES = [
    "../lib/addnumbers.js",
].map(function(file){
    return require.resolve(file);
});

This format fails with the ncc run <filename> command.

Possibly a duplicate of #41

Here's a simple repo to demonstrate the issue : https://github.com/bfulop/zeitwithyarn

It fails with this error:

	var e = new Error("Cannot find module '" + req + "'");
         ^
Error: Cannot find module '../lib/addnumbers.js'
    at Function.webpackEmptyContext [as resolve] (/private/var/folders/r2/br0p741168qg5n2h65fzsdz40000gn/T/d41d8cd98f00b204e9800998ecf8427e/index.js:84:10)
    at /src/addtwo.js:6:1
    at Array.map (<anonymous>)
    at Object.457 (/src/addtwo.js:5:1)
    at __webpack_require__ (/webpack:bootstrap:19:1)
    at Object.138 (/date.js:1:1)
    at __webpack_require__ (/webpack:bootstrap:19:1)
    at startup (/webpack:bootstrap:33:1)
    at /webpack:bootstrap:37:1
    at Object.<anonymous> (/private/var/folders/r2/br0p741168qg5n2h65fzsdz40000gn/T/d41d8cd98f00b204e9800998ecf8427e/index.js:43:10)
@homerjam
Copy link

homerjam commented Mar 9, 2019

Would/does specifying externals work?

@bfulop
Copy link
Author

bfulop commented Mar 10, 2019

I haven't tried that. In this case, I would need to deploy to Zeit the output of the ncc build run?

My workaround was to pre-bundle the MJML package with NCC, publish it to npm, and import that in my app. This way I can just do $ now and it works.

https://www.npmjs.com/package/mjml-ncc-bundle

@homerjam
Copy link

Yes, thats how I understand it. Although I'm not sure it's possible, I think it may require a modification to the now-node builder to allow specify the ncc options.

Thanks for letting me know about the workaround - I'll do the same for now!

@homerjam
Copy link

I've tested using externals and can confirm this appears to work

ncc run index.js -e uglify-js

@guybedford
Copy link
Contributor

Since this is such a common problem, we've included this as the default behaviour in #307.

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

4 participants