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

browserify-adventure writing transforms #11

Open
lokken opened this issue Aug 20, 2015 · 0 comments
Open

browserify-adventure writing transforms #11

lokken opened this issue Aug 20, 2015 · 0 comments

Comments

@lokken
Copy link

lokken commented Aug 20, 2015

I'm posting an issue I had with the browserify-adventure "writing transforms" lesson and it's solution because it caused me a fair amount of headache.

The issue was that running a correct solution, even the reference solution, would fail.

$ browserify -t ./tr.js main.js

/usr/local/lib/node_modules/browserify-adventure/problems/using_transforms/wake.txt:1
Be that as it may, but for that light phantastic of his gnose's glow as it
   ^
ParseError: Unexpected token

The problem has nothing to do with your code but instead is because the wake.txt file is in a node_modules directory, and is discussed here: browserify/browserify#515. Essentially, by default you can't use a transform on a module that requires a file that lives in a node_modules directory, because by design browserify only transforms top-level modules, i.e. modules not in node_modules.

There are 2 solutions. You can either copy the wake.txt file to a directory outside of the node_modules directory, e.g. your current working directory, or you can specify the --global-transform (-g) option at the command prompt. In my opinion, it's probably better to just copy the file rather than use the global transform option, since using global transform is "dangerous" and not something you'd want to use in the future unless you really understand why you're using it.

Solution 1

$ cp /usr/local/lib/node_modules/browserify-adventure/problems/using_transforms/wake.txt ~/dev/node/browserify-adventure/

In main.js

var txt = require("./wake.txt");
console.log(txt);

Solution 2

$ browserify -g ./tr.js main.js | browserify-adventure verify

The issue is also addressed in the browserify-adventure issues, workshopper/browserify-adventure#20.

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

1 participant