-
Notifications
You must be signed in to change notification settings - Fork 8
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
Version 4 in Node complains about "Cannot use import statement outside a module" #619
Comments
Uch! I'm really sorry this happened to you 😞Have you tried importing the bundled version as described in the migration guide? https://github.com/no-chris/chord-symbol/blob/master/packages/chord-symbol/MIGRATION.md let me know if importing the bundled version solves your problem. Sorry again about this! |
I'm using typescript and the following from the migration guide does not work, at least not in my typescript project: The error message is: And @types/chord-symbol does not exist. |
Seems that it complains about not finding types... I'm not a typescript expert, can you try as it says, e.g. adding |
Thanks! What worked was: import { And then I created a new chord-symbol.d.ts file in the same folder where I added the following: I do not know how to fix this in your library, but at least I can manually fix the issues by creating my own copy of the index.d.ts file. |
I'm glad you found a workaround! |
Here is a github repository that shows both the error and the workaround: There are two tags, one with a "normal version 3" and one with a "version 4" with workaround: If you checkout the version 3 tag, and update chord-symbol to version 4 in package.json, you will get the error mentioned in the issue both when running tests and executing the cli: Run with: and Run test with Cheers |
Amazing, thanks a lot, I will have a look asap |
This should probably fix it, I basically implemented your solution, on my side it seems to work, would you have any way to test? |
And actually declaring the module with the |
I am happy to verify if this works, but I don't know how I can? I also tried to clone your repository locally but get lots of errors when i try "yarn build". I don't know if I need to build a version locally or if there is a way for me to test your branch in my node project without building it locally ? (like the github question above) |
Good question... I could release a beta version but with lerna I think it means that I need to merge to master first, which I'd rather avoid before having it tested... I think the easiest way would be to clone the repository directly in the node_modules and then checkout the branch
About the other issue did you run |
Once the testing is done you can just remove the repository and run yarn install again
(untested) |
Unfortunately I just cannot get it to work without creating a local copy of the file. First I clone the repository in node_modules using the commands you listed. If I only use If I use the modified I even tried to run your commands and copy up the chord-symbol package directory to the main node_modules directory but this did not change anything. So the only thing I made work was to reset to the original 4.0.0 version of your library and add the chord-symbol.d.ts manually using a copy of your file pasted into the same directory as package.json and remembered to use the .js import: |
First of all, thanks for a very good library!
I have spent more than 5 hours trying to upgrade my typescript node project to work after the changes between version 3 and 4, and have at this moment given up and rolled back to version 3.
The error given when running the program is:
SyntaxError: Cannot use import statement outside a module:
The error happens in:
/node_modules/chord-symbol/src/index.js:1
import './typedefs';
^^^^^^
SyntaxError: Cannot use import statement outside a module
I tried following several tutorials to see if setting typescript compiling to esnext and setting type to "module" in package.json would work but had to give up after hours of errors.
I also tried to see if it was only the first import line that stopped this from working, but then it fails on the second import in the same index.js file, so for some reasons all "imports" have stopped working.
I'm noe sure what changed between version 3 and 4 that made a standard typescript node project stop working, but I can confirm that chord-symbol version 4 works perfectly in react native expo.
Here are some tutorials I tried, but none of them helped.
https://stackoverflow.com/questions/71929951/typescript-syntaxerror-cannot-use-import-statement-outside-a-module-side-file
https://stackoverflow.com/questions/74766930/syntaxerror-cannot-use-import-statement-outside-a-module-in-nodejs-typescript
The text was updated successfully, but these errors were encountered: