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

Module issues with Webpack #48

Open
johnnysprinkles opened this issue Jun 10, 2019 · 11 comments
Open

Module issues with Webpack #48

johnnysprinkles opened this issue Jun 10, 2019 · 11 comments

Comments

@johnnysprinkles
Copy link

johnnysprinkles commented Jun 10, 2019

I have a Javascript project that's compiled with Webpack/Babel for use in NodeJS runtime, and when I try to depend on cowsay I get this error at compile time:

[node] Error: Cannot find module '.cows/ackbar.cow'
[node]     at webpackMissingModule (webpack:///./node_modules/cowsay/build/cowsay.es.js?:50:45)
[node]     at eval (webpack:///./node_modules/cowsay/build/cowsay.es.js?:50:136)
[node]     at Module../node_modules/cowsay/build/cowsay.es.js (/local/home/simnsj/workspace/nodetemplate/src/NodeStarterTemplate/dist/server/main.js:782:1)
...

My code for including cowsay looks something like this:

import cowsay from 'cowsay';

class Cowsay extends React.Component {
  render() {
    return <div>{cowsay.say({text: this.props.children})}</div>;
  }
}

I don't understand javascript modules that well, and I think they're a moving target...

@johnnysprinkles johnnysprinkles changed the title Module issues with Babel Module issues with Webpack Jun 10, 2019
@piuccio
Copy link
Owner

piuccio commented Jun 11, 2019

Hmm it looks weird.
Are you trying to render react code on the server?
Might be that you're missing a file loader, the .cow files should be loaded as text.
Is your project public? Maybe I can have a look

@johnnysprinkles
Copy link
Author

It's not but I'll boil down to a repro case, soon.

@foxundermoon
Copy link

same issue .
on next.js server render

Failed to compile.

./node_modules/cowsay/build/cowsay.umd.js
Module not found: Can't resolve '.cows/C3PO.cow' in '/Volumes/data/workspace/github/foxmn/web-tools/show-user-agent/node_modules/cowsay/build'

@foxundermoon
Copy link

import cowsay from "cowsay";
...
IndexPage.getInitialProps = async function({ req, res }) {
  const isServer = typeof window === "undefined";
  if (notBrowser) {
    const say = chalk.blueBright('xxxxxxxxxx');
    res?.write(cowsay.say({ text: say, f: "cat" }));
    res?.end();
  }
  return {
   ...
  };
};

@mkly
Copy link

mkly commented Jan 19, 2020

I had some success using

resolve: {
  alias: {
    ".cows": "cowsay/cows"
  },
},

Enjoy your cows! 🐄

@johnnysprinkles
Copy link
Author

I ended up kind of forking this project, with pure Javascript cows instead of text file Perl cows. I think JS Cows are the Cows of the future. https://github.com/johnnysprinkles/cowsay/tree/master/cows

@piuccio
Copy link
Owner

piuccio commented Jan 21, 2020

@johnnysprinkles if you argument better why that's better and send a PR, I might merge it...

@johnnysprinkles
Copy link
Author

That would be a sizeable PR! And probably warrant a v2 release. This fork also does a number of other things, curious how much you'd be interested in a PR for all these things:

  • Update to modern style (var => let, single quotes, 2-space tabs, etc)
  • Update to modern language features, e.g. max can be a one-liner using array spread
  • Update to the top level API to make the text be a first positional parameter, and all the other options in a second object param
  • Pure Javascript cows using template literals. I'm using the Perl heredoc literals almost unchanged, but the "superfluous escapes" mentioned in cowfile fixes #50 are no longer an issue this way
  • Rewrote balloon#split() to handle word breaking correctly
  • The code to convert Perl heredoc to JS template is under util/ but really that doesn't even need to be included, could go in a gist or somewhere. But some things in your cowsay could be removed like replacer.js and all the .cow files.
  • ESLint checks

@piuccio
Copy link
Owner

piuccio commented Jan 22, 2020

If you care about having them upstream, send some PR, I'll review (best to separate in multiple PRs)

@johnnysprinkles
Copy link
Author

Hmm, it's diverged quite a bit, not really a fork more like looking at your implementation for reference. I guess I'm trying to gauge your interest in owning and maintaining NPM cowsay, sounds like you are still interested.

@piuccio
Copy link
Owner

piuccio commented Jan 22, 2020

Up to you, if you feel like your code would benefit the people using npm cowsay we can try to converge. I don't mind having you as contributor if it makes sense.

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