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

Error: Can't resolve './..__target__src.main.js' #624

Open
jalbr74 opened this issue Mar 21, 2019 · 8 comments
Open

Error: Can't resolve './..__target__src.main.js' #624

jalbr74 opened this issue Mar 21, 2019 · 8 comments
Labels

Comments

@jalbr74
Copy link

jalbr74 commented Mar 21, 2019

Hi, I'm new to Transcrypt, but I love the concept!

I thought I'd try a simple "Hello World" project, but I'm running into the following error when I build using webpack:

ERROR in ./src/main.py
Module not found: Error: Can't resolve './..__target__src.main.js' in 'C:\project\src'
 @ ./src/main.py 1:0-44 1:0-44
 @ multi (webpack)-dev-server/client?http://localhost:8081 ./src/main.py

The only thing that stands out to me is the folder path:

./..__target__src.main.js

My guess is it should actually be:

./../__target__/src.main.js

I'm running on Windows 10, and I'm not sure if it's a problem with building paths on Windows, or because I'm doing something wrong.

It builds fine when I run:

transcrypt src/main.py

Is there any other info I should Include?

OS: Windows 10
Python: 3.7.2
Node: v10.15.1
NPM: 6.4.1

@jalbr74
Copy link
Author

jalbr74 commented Mar 21, 2019

Here's a link to my Hello World project:
https://github.com/jalbr74/hello-transcrypt

@bunkahle
Copy link

Hi,
you can find a kind of tutorial for transcrypt at:
https://github.com/bunkahle/Transcrypt-Examples/tree/master/hello
or
https://github.com/bunkahle/Transcrypt-Examples
where you find more information how to take the first basic steps.

@jalbr74
Copy link
Author

jalbr74 commented Jul 2, 2019

It's been a while since I've been able to get back to this project, but I was able to figure out a fix for the problem. It looks like there is an issue in transcrypt-loader when run on Windows.

I had to edit the following file: ./node_modules/transcrypt-loader/__target_es5__/index.js

On line 44, the code was calling path.relative as follows:

var import_path = './' + path.relative(fileinfo.dir, target_path);

This returned the string: ..\__target__\src.main.js, which caused import_path to be: ./..\__target__\src.main.js, which wasn't a valid path when used in the code farther down:

return 'export * from "{}";'.format(import_path);

The fix I used was to call replace() on the string, and change all back slashes to forward slashes:

var import_path = './' + path.relative(fileinfo.dir, target_path).replace(/\\/g, '/');

In the end, it appears to be a problem with running transcrypt-loader on Windows, due to differences in the path separator. I'd be happy to contribute a pull request, but I couldn't find the transcrypt-loader source in this repo, and I couldn't find another project in GitHub for it either. Is there another place this project is being shared?

@JdeH
Copy link
Collaborator

JdeH commented Aug 14, 2019

Hi, sorry that you stumbled into this.
Support for bundlers was added only recently and the demo at transcrypt/demos/webpack actually uses a patched version.

I'll contact the original developer to solve the problem, taking into account your solution.
We still have to confere on where to host the project for this, and the link on https://www.npmjs.com/package/transcrypt-loader states that it's in the Transcrypt project which is not (yet) the case.

Meanwhile thanks for the detective work!

@JdeH JdeH added the IS: bug label Aug 14, 2019
@koeninger
Copy link

@JdeH is there anything I can do to help resolve this? We'd be happy to host the transcrypt loader on the cloudflare github if need be.

@phistrom
Copy link

phistrom commented Aug 7, 2020

I managed to find the source code for the transcrypt-loader npm package. It appears to only live in a branch called "parcel-bundler2". I have submitted a pull request but I think @doconix will need to do the actual uploading if it is approved.

@JennaSys
Copy link
Collaborator

Just FYI, this same problem exists in the parcel-plugin-transcrypt package as well. It works with the above workaround by adding replace() on line 46 in asset.js and changing it from

this.importPath = './' + path.join('__target__', this.pyModule) + '.js';

to

this.importPath = ('./' + path.join('__target__', this.pyModule) + '.js').replace(/\\/g, '/');

The default package config in the same file that uses python3 was an issue on Windows as well, though that can be fixed by putting a custom config in package.json (though not really ideal).

@JennaSys
Copy link
Collaborator

JennaSys commented Feb 3, 2022

For anyone interested, because the new version of Parcel uses a plugin system that is completely incompatible with the older version, I recently created and published a new Python transformer for Parcel V2 that uses Transcrypt. So far it has handled all of the different environments and platforms I've tried it on. But if you run into any problems with it, feel free to open up a GitHub issue and I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants