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

Cannot find module 'strtok3/core' from 'node_modules/file-type/core.js' #548

Closed
Matthew-McRaven opened this issue Jun 10, 2022 · 10 comments · Fixed by #553
Closed

Cannot find module 'strtok3/core' from 'node_modules/file-type/core.js' #548

Matthew-McRaven opened this issue Jun 10, 2022 · 10 comments · Fixed by #553

Comments

@Matthew-McRaven
Copy link

Hello,

I have version 17.1.2 installed in a project.

When I attempt to use this library I get the error Cannot find module 'strtok3/core' from 'node_modules/file-type/core.js'

This seems to be caused by core.js:3 referencing strtok3/core instead of strtok3/lib/core.

Maybe this is a problem with my local setup, but wanted to see if there was an easy resolution to this issue.

@marcegige
Copy link

@Matthew-McRaven I'm having the same issue, did you find a solution to it?

@sindresorhus is there any coming update to fix this?

@Matthew-McRaven
Copy link
Author

I ended up forking the project and fixing the import paths.

@anton000
Copy link

@Matthew-McRaven i think you should just do a pull req on the package.json quick fix

@Matthew-McRaven
Copy link
Author

Matthew-McRaven commented Jul 12, 2022

@anton000, This isn't a package.json fix. You have to modify core.js:3 and fix the import path.

I'm not entirely confident that this error isn't an artifact of my build environment (yarn 3 using lerna in a monorepo), so I opted for a fork with the fixes.

If the author of the project or another maintainer can replicate the bug in a less specialized environment, I'd happily submit a PR.

@seanmoghadam
Copy link

seanmoghadam commented Jul 27, 2022

also facing the same issue after updating from 16.4.0 to 17.1.4

api_1       | ERROR in ./node_modules/file-type/index.js
api_1       | Module not found: Error: Can't resolve 'strtok3' in '/code/node_modules/file-type'
api_1       | 
api_1       | ERROR in ./node_modules/file-type/core.js 681:28
api_1       | Module parse failed: Identifier directly after number (681:28)
api_1       | 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
api_1       | | 				while (children > 0) {
api_1       | | 					const element = await readElement();
api_1       | > 					if (element.id === 0x42_82) {
api_1       | | 						const rawValue = await tokenizer.readToken(new Token.StringType(element.len, 'utf-8'));
api_1       | | 						return rawValue.replace(/\00.*$/g, ''); // Return DocType

UPDATE:
I just wanted to update this dependency because of the security issue wit the malformed mkv file. I just found out that npm audit can also fix this issue by bumping the sub-dependency:
npm update file-type --depth 1

Issue solved for me.

@Borewit
Copy link
Collaborator

Borewit commented Jul 29, 2022

file-type version 17 is an ES-Module, version 16 and below is CommonJS. If you do not run from an ESM project yourself, you can expect issues going from 16 to 17.

Related issues: #541, #535, #525, #515, #502

See also: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

@Borewit Borewit closed this as completed Jul 29, 2022
@Borewit
Copy link
Collaborator

Borewit commented Aug 3, 2022

The path 'strtok3/core' was wrong indeed, sorry issue was hard to distinct from the many basic ESM issues.
Issue fixed by:

@Borewit Borewit linked a pull request Aug 3, 2022 that will close this issue
abdulghani added a commit to abdulghani/file-type that referenced this issue Mar 6, 2023
@Nases
Copy link

Nases commented Aug 8, 2024

lib folder is missing on strtok3 package 8.0.2, try downgrading to 8.0.1 (this is a dependency of file-type)
issue -> Borewit/strtok3#1143

You can confirm this by ls node_modules/strtok3 and you might only see LICENSE package.json README.md, no source code exported.

@AnonymousSausage77
Copy link

Woah Nases, what a timely answer. That worked for me

@Borewit
Copy link
Collaborator

Borewit commented Aug 8, 2024

lib folder is missing on strtok3 package 8.0.2, try downgrading to 8.0.1 (this is a dependency of file-type) issue -> Borewit/strtok3#1143

You can confirm this by ls node_modules/strtok3 and you might only see LICENSE package.json README.md, no source code exported.

Issue Borewit/strtok3#1143, has been resolved in [email protected]

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

Successfully merging a pull request may close this issue.

7 participants