0

I am trying to integrate Wetty API with a simple ReactJS project. I first ran into the shebang error.

ERROR in ./node_modules/wetty/build/main.js 1:0
Module parse failed: Unexpected character '#' (1:0)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
> #!/usr/bin/env node
| import yargs from 'yargs';
| import { createRequire } from 'module';
 @ ./src/components/App.js 4:0-30
 @ ./src/index.js

When I added webpack to the project, and added shebang2-loader to process the Wetty node module, the shebang error went away. However, I am getting another error that is not descriptive (see below). I configured the babel-loader to process ReactJS files.

ERROR in ./node_modules/wetty/build/main.js 6:36
Module parse failed: Unexpected token (6:36)
File was processed with these loaders:
 * ./node_modules/shebang2-loader/index.js
You may need an additional loader to handle the result of these loaders.
| import { start } from './server.js';
| import { loadConfigFile, mergeCliConf } from './shared/config.js';
> const require = createRequire(import.meta.url);
| const packageJson = require('../package.json');
| const opts = yargs
 @ ./src/components/App.js 4:0-30
 @ ./src/index.js

When I commented out importing Wetty line, and added the importing yargs to my own JS file, I also got a similar error message:

ERROR in ./node_modules/yargs/lib/platform-shims/esm.mjs 20:34
Module parse failed: Unexpected token (20:34)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| let __dirname;
| try {
>   __dirname = fileURLToPath(import.meta.url);
| } catch (e) {
|   __dirname = process.cwd();
 @ ./node_modules/yargs/index.mjs 4:0-59 7:27-42
 @ ./src/index.js

So it seems like there might be some issue with "import.meta.url".

Steps to reproduce the behavior:

  1. Create a simple ReactJS project In a project file
  2. Add the line "import { start } from 'wetty';"
  3. Add both babel-loader and shebang2-loader to the webpack config file
  4. Run the project and see the error.

I am using the following environment: OS: Windows Linux subsystem - Ubuntu

1 Answers1

0

Issue resolved. I was using webpack version 4. upgraded to 5. Still had issue with polyfill, but was able to resolve that with How to Polyfill node core modules in webpack 5