Babel-loader: Unexpected character '#'

Created on 8 Nov 2017  路  9Comments  路  Source: babel/babel-loader

When I try to require sqlite3 I got error:

ERROR in ./~/sqlite3/~/rc/index.js
Module parse failed: .../node_modules/sqlite3/node_modules/rc/index.js Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| #! /usr/bin/env node
| var cc   = require('./lib/utils')
| var join = require('path').join
 @ ./~/sqlite3/~/node-pre-gyp/lib/publish.js 14:13-26
 @ ./~/sqlite3/~/node-pre-gyp/lib ^\.\/.*$
 @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js
 @ ./~/sqlite3/lib/sqlite3.js
 @ ./spec/videopage.js
 @ ./spec/index.js
 @ multi webpack-hot-middleware/client babel-polyfill ./spec/index.js

Webpack config:

    resolve: {
        extensions: [
            '.js', '.jsx', '.css', 'json'
        ],
        modules: ['node_modules']
    },
    node: {
        fs: "empty",
        dns: "empty",
        net: "empty",
        tls: "empty",
        "child_process": "empty"
    },
    module: {
        rules: [
            {
                test: /\.json$/,
                loader: 'json-loader'
            }, {
                test: /\.js$/,
                use: 'babel-loader',
                include: [
                    path.join(__dirname, '../components'),
                    path.join(__dirname, '../spec')
                ]
            }
...

.babelrc

  "presets": ["es2015", "stage-0", "react"]
...

Most helpful comment

All 9 comments

Hm thanks for the issue!

You shouldn't need to run Babel on node_modules like sqlite? It should be excluded right?

You shouldn't need to run Babel on node_modules like sqlite? It should be excluded right?

Yep, I think necessary to remove all strings with #!/usr/bin/env node from all dependencies of Sqlite module. But how?

Oh what I mean is you should do something like

{
   test: /\.js$/,
   use: 'babel-loader',
+  exclude: /node_modules/,
}

Didn't help

This is not a Babel issue. See https://github.com/JavascriptIsMagic/shebang-loader and webpack/webpack#2168

I tried everything but problem still there: Unexpected character '#' (1:0)
I absolutely unserstand the problem with '#' /usr/bin/env node but can't wrap it. No one solution not help.

You should be able to load shebang-loader and have it run on your node_modules.

That said, sqlite3 is a node-only module. Bundling it with Webpack probably isn't going to work either way. I'm not sure what you're trying to do, but this issue isn't the proper place to seek support. babel-polyfill shows up in your error message entirely by chance.

Thanks. I found another solution with middleware https://github.com/Spikef/sync-sqlite

Was this page helpful?
0 / 5 - 0 ratings