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

TypeError: Filename must be a string #5

Closed
AndrewRayCode opened this issue May 13, 2015 · 8 comments
Closed

TypeError: Filename must be a string #5

AndrewRayCode opened this issue May 13, 2015 · 8 comments

Comments

@AndrewRayCode
Copy link

I'm not sure what's causing this yet. I will close this bug if it turns out to be our fault. I included the babel rewire plugin in our webpack config:

babel-loader?plugins=rewire&optional=runtime

When I run webpack (building our test bundle), I get:

ERROR in vendors.js
Module build failed: TypeError: Filename must be a string

The content of vendors.js aren't anything exciting:

require('react');
require('lodash');
require('react-router');

The stack trace exits at

at Object.module.exports (/node_modules/babel-loader/index.js:43:24)

so I'm not sure what's originating the error. If I log inside that line to see what filename is it prints out a very large object that isn't immediately recognizable.

Does this plugin still work with regular require statements alongside es6 import statements? Actually, even if I make the contents of that file only import "react"; it gives me the same error...

Might be worth noting I'm using rewire-webpack, although this error still persists if I remove rewire-webpack it from my webpack plugins list.

@AndrewRayCode
Copy link
Author

I lied, this error is coming from the rewire plugin, not this plugin

@AndrewRayCode
Copy link
Author

Well, I lied again. this error only seems to happen if I include this plugin. Still investigating...

@speedskater
Copy link
Owner

Might it be possible that you are using rewire.js along babel-plugin-rewire? If this is the case can you check whether the error remains if you change babel-loader?plugins=rewire&optional=runtime to
babel-lodaer?plugins=babel-plugin-rewire

@AndrewRayCode
Copy link
Author

I changed it to loader: 'babel-loader?plugins=babel-plugin-rewire'. Webpack gives the warning (followed by lots of errors in rewire):

WARNING in ./~/rewire/lib/moduleEnv.js
require.extensions is not supported by webpack. Use a loader instead.

What do you mean using rewire.js along with the plugin? We do this in plenty of places in the code:

let rewire = require('rewire');

Sorry for my density - I'm not familiar with the internals of rewire - I assumed this plugin did some magic to allow require('rewire') to still work. Is that not the case? Looking at the readme it appears that the API is automatically injected into all classes that are imported? Is that correct?

@AndrewRayCode
Copy link
Author

Tested in a blank project, simply adding this line:

var rewire = require('rewire');

Triggers the errors/warnings:

WARNING in ./~/rewire/lib/moduleEnv.js
require.extensions is not supported by webpack. Use a loader instead.

WARNING in ./~/rewire/lib/moduleEnv.js
Module not found: Error: Cannot resolve module 'coffee-script' in node_modules/rewire/lib
@ ./~/rewire/lib/moduleEnv.js 103:13-37

ERROR in ./~/rewire/lib/rewire.js
Module not found: Error: Cannot resolve module 'module' in node_modules/rewire/lib
@ ./~/rewire/lib/rewire.js 22:13-30

However, if I add this to the webpack config in the blank project:

var RewirePlugin          = require("rewire-webpack");
....
plugins: [
      new RewirePlugin()
]

Then the bundle is valid. More investigation required...

@AndrewRayCode
Copy link
Author

Something is conflicting somewhere with babel and rewire. In the large project, what's getting built to the bundle is:

exports['default'] = _Object$assign(var MyReactClass = (function (_React$Component) {

which throws the error Unexpected token var in the webpack build step. It looks like turning ES6>ES3 is getting wrapped in a rewire statement, but the syntax produced is wrong. I cannot yet reproduce this in small test project

@speedskater
Copy link
Owner

Have you tried the latest version (0.1.3) of babel-plugin-rewire this should fix the problem with the wrapping of the default export

AndrewRayCode added a commit to AndrewRayCode/babel-plugin-rewire that referenced this issue May 14, 2015
To avoid conflicts with npm `require` module

Inspired by speedskater#5
@AndrewRayCode
Copy link
Author

Phew, ok, looks like using the explicit name and the newest version works.

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

2 participants